asp.net core發(fā)布到iis后出現(xiàn)錯(cuò)誤嚣伐,An error occurred while starting the application别瞭,站點(diǎn)啟動(dòng)不了慌洪,這個(gè)提示很難發(fā)現(xiàn)問(wèn)題的所在策严。
錯(cuò)誤原文如下:
An error occurred while starting the application.
NET Core 4.6.26328.01 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.2.7-rtm-10026 | Microsoft Windows 10.0.16299 | Need help?
解決問(wèn)題的第一步肯定是先找到錯(cuò)誤原因穗慕,
解決辦法,先打開iis日志妻导。web.config 修改如下
<aspNetCore requestTimeout="23:00:00" processPath="dotnet" arguments=".\XX.Web.dll" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" startupTimeLimit="3600">
<environmentVariables />
</aspNetCore>
需要把stdoutLogEnabled值false設(shè)置為true
如果沒(méi)有發(fā)現(xiàn)該節(jié)點(diǎn)就復(fù)制一份過(guò)去, 記得把XX.Web.dll改成自己的名字逛绵。
<aspNetCore processPath="dotnet" arguments=".\XX.Web.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
完成的config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<!-- Remove WebDAV module so that we can make DELETE requests -->
<remove name="WebDAVModule" />
</modules>
<handlers>
<!-- Remove WebDAV module so that we can make DELETE requests -->
<remove name="WebDAV" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<!-- When deploying on Azure, make sure that "dotnet" is installed and the path to it is registered in the PATH environment variable or specify the full path to it -->
<!-- 注意,修改這里/ -->
<aspNetCore requestTimeout="23:00:00" processPath="dotnet" arguments=".\XX.Web.dll" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" startupTimeLimit="3600">
<environmentVariables />
</aspNetCore>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<!-- Protects against XSS injections. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ -->
<add name="X-XSS-Protection" value="1; mode=block" />
<!-- Protects against Clickjacking attacks. ref.: http://stackoverflow.com/a/22105445/1233379 -->
<add name="X-Frame-Options" value="SAMEORIGIN" />
<!-- Protects against MIME-type confusion attack. ref.: https://www.veracode.com/blog/2014/03/guidelines-for-setting-security-headers/ -->
<add name="X-Content-Type-Options" value="nosniff" />
<!-- Protects against Clickjacking attacks. ref.: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security_Cheat_Sheet -->
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
<!-- CSP modern XSS directive-based defence, used since 2014. ref.: http://content-security-policy.com/ -->
<add name="Content-Security-Policy" value="default-src 'self'; connect-src * data:; font-src *; frame-src *; img-src * data:; media-src *; object-src *; script-src * 'unsafe-inline' 'unsafe-eval'; style-src * 'unsafe-inline'; worker-src blob:" />
<!-- Prevents from leaking referrer data over insecure connections. ref.: https://scotthelme.co.uk/a-new-security-header-referrer-policy/ -->
<add name="Referrer-Policy" value="strict-origin" />
<!--Feature-Policy is a new header that allows a site to control which features and APIs can be used in the browser. ref.: https://wicg.github.io/feature-policy/ -->
<add name="Feature-Policy" value="accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment *; usb 'none'" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering>
<!--文件上傳限制-->
<requestLimits maxAllowedContentLength="1073741822" />
<!-- 1GB-->
</requestFiltering>
</security>
</system.webServer>
</configuration>
<!--ProjectGuid: 4f1f649c-1020-45be-a487-f416d9297ff3-->
修改了再次啟動(dòng)網(wǎng)站倔韭,就會(huì)找到錯(cuò)誤术浪,定位到錯(cuò)誤了改起來(lái)就簡(jiǎn)單了!寿酌!
結(jié)束R人铡!