.NET 5 Incorrect response MIME type. Expected 'application/wasm'

391 views Asked by At

I have a mvc project on net 5 and I have to be able to work with .wasm files.

I have done the following in the configure of the Startup.cs

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = context =>
    {
       IHeaderDictionary headers = context.Context.Response.Headers;
       string contentType = headers["Content-Type"];
       if (contentType == "application/x-gzip")
       {
          if (context.File.Name.EndsWith("js.gz"))
          {
              contentType = "application/javascript";
          }
          else if (context.File.Name.EndsWith("css.gz"))
          {
              contentType = "text/css";
          }
          headers.Add("Content-Encoding", "gzip");
          headers["Content-Type"] = contentType;
       }
    },                     
    ContentTypeProvider = new FileExtensionContentTypeProvider() { 
          Mappings = {[".wasm"] = "application/wasm" },
    },
    DefaultContentType = "application/octet-stream"
});

I can't get the .wasm files I get the following error.

wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

How can I do to be able to read this type of files?

It only happens to me with this type of files, the rest work correctly

0

There are 0 answers