ASP.NET Core MVC project does not display Unity WebGL content

Viewed 360

I am developing an ASP.NET Core MVC project and I need to embed a Unity WebGL game into one of the pages. I tried looking in a lot of places online but all of them use the older versions of Unity and thus the contents of the WebGL build look different.

The WebGL build works fine by itself (when I press Build and Run in Unity), but does not work when I try to put it in my MVC.

What I tried so far:

Changing the Configure method to use static content:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { 
    if (env.IsDevelopment()) { 
        app.UseDeveloperExceptionPage(); 
    } else { 
        app.UseExceptionHandler("/Home/Error"); 
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https:// 
        app.UseHsts(); 
    }
    
    app.UseHttpsRedirection();

    app.UseDefaultFiles(); 
    app.UseFileServer(); 
    StaticFileOptions options = new StaticFileOptions(); 
    FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)options.ContentTypeProvider ?? new FileExtensionContentTypeProvider(); 
    contentTypeProvider.Mappings.Add(".unityweb", "application/octet—stream"); 
    options.ContentTypeProvider = contentTypeProvider; app. UseStaticFiles(options); 

    app.UseRouting(); 
}

Configure Method:

Configure Method

Adding web.config file

<system.webServer>
    <staticContent>
        <remove fileExtension=".unityweb" I>
        <mimeMap fileExtension=".unityweb" mimeType="application/octet—stream" />
    </staticContent>
</system.webServer> 

The web.config file:

web.config file

And placing the Build and index.html from the WebGL build in wwwroot:

directory

When I build, it opens the index.html file but with nothing in the box where the game is supposed to play: Build screen

The errors in the Console say that the file was not found even though it is in the Build folder: errors directory

index.html file: index.html

Any help would be appreciated!

Thank you!

1 Answers

For anyone wondering, this was resolved by downgrading Unity to 2019.

Related