After Unity packages the WebGL project, an error message appears when opening the html page locally.
Failed to download file Build/Unity Web.data.gz. Loading web pages via a file:// URL without a web server is not supported by this browser.
I tried several methods online, and finally it worked. Here are the solution steps:
1. Open the Web service , open the Control Panel-->Programs-->Enable or turn off functions-->Internet Infomation Services, check all boxes and confirm.
2. Website configuration , click on this computer, right-click-->Manage-->Services and Applications-->Internet Infomation Services--Website
3. Create a new website:
First, place the packaged WebGL project in the corresponding path (for example: E:\WebGlTest\TestWebGL_LaoZhaSheBei)
Then click Website-->Create a new website
Add the Web.config configuration file in the folder where the project is located
web.config :
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.webServer>
<httpProtocol>
<!-- 允许跨域配置 -->
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type,Authorization" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
<staticContent>
<remove fileExtension=".mem" />
<remove fileExtension=".data" />
<remove fileExtension=".unity3d" />
<remove fileExtension=".jsbr" />
<remove fileExtension=".membr" />
<remove fileExtension=".databr" />
<remove fileExtension=".unity3dbr" />
<remove fileExtension=".jsgz" />
<remove fileExtension=".memgz" />
<remove fileExtension=".datagz" />
<remove fileExtension=".unity3dgz" />
<remove fileExtension=".json" />
<remove fileExtension=".unityweb" />
<mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
<mimeMap fileExtension=".data" mimeType="application/octet-stream" />
<mimeMap fileExtension=".unity3d" mimeType="application/octet-stream" />
<mimeMap fileExtension=".jsbr" mimeType="application/octet-stream" />
<mimeMap fileExtension=".membr" mimeType="application/octet-stream" />
<mimeMap fileExtension=".databr" mimeType="application/octet-stream" />
<mimeMap fileExtension=".unity3dbr" mimeType="application/octet-stream" />
<mimeMap fileExtension=".jsgz" mimeType="application/x-javascript; charset=UTF-8" />
<mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
<mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
<mimeMap fileExtension=".unity3dgz" mimeType="application/octet-stream" />
<mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
<mimeMap fileExtension=".unityweb" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
Finally, enter: 127.0.0.1:8080 on the web page to check the effect. At this time, you may encounter a problem that the configuration file cannot be opened due to insufficient permissions.
Right-click the folder->Properties->Security, click Edit, add the Everyone user and give it all permissions
Finally, refresh the web page to open the generated WebGL project.
Reference links: