美文网首页
asp.net core发布到iis后出现An error oc

asp.net core发布到iis后出现An error oc

作者: zxws1009 | 来源:发表于2021-01-12 17:06 被阅读0次

    asp.net core发布到iis后出现错误,An error occurred while starting the application,站点启动不了,这个提示很难发现问题的所在。

    错误原文如下:

    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?

    解决问题的第一步肯定是先找到错误原因,

    解决办法,先打开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设置为true

    如果没有发现该节点就复制一份过去, 记得把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-->
    

    修改了再次启动网站,就会找到错误,定位到错误了改起来就简单了!!

    结束!!

    相关文章

      网友评论

          本文标题:asp.net core发布到iis后出现An error oc

          本文链接:https://www.haomeiwen.com/subject/jsdeaktx.html