简体   繁体   中英

How to troubleshoot problems with web.config when deploying an ASP.NET Core Web API project to IIS

I have built an ASP.NET Core Web API in Visual Studio 2017 using the Web API template. When I test it during development it runs using IIS Express and works as expected. The index.html file is served from the wwwroot folder, makes some AJAX requests to the ASP.NET server which makes some HTTP requests to a third party API to obtain some data which is eventually returned to the browser. No datbase involved. I tried to publish to IIS so that another person at my company can use it locally on their machine (which will have IIS running). I published through Visual Studio 2017's publisher:

Right click on project and publish to IIS (following directions from this tutorial: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis )

When I publish, a web page opens with the URL I put as the destination URL: localhost/ProjectName but I get this error: HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.

There is not config error identified on that screen. Here's what my web.config looks like:

  <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <handlers>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
    resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".\StandardsGenerator.dll" 
    stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      </system.webServer>
    </configuration>
    <!--ProjectGuid: 78162755-cd01-4a5c-8863-1087bd7f6f8f-->

Is there something wrong with this configuration? If anyone can point to resources that describe what should be in a web.config file that may be helpful.

Also, when I publish the app and navigate to localhost/ProjectName I expect an index.html file to be served from the wwwroot directory. In my test environment I configured this in my LaunchSettings.json. Where do I configure the start page for a published app?

Regarding 500.19 errors, there are multiple reasons why you could encounter this error. To troubleshoot this further, please enable detailed errors for this application from IIS. To do so, launch IIS, select the specific website. Open Error pages section in the center panel. Right click on the page and select "Edit Feature Settings". Choose "Detailed errors" here. You can also follow this blog which speaks on the same lines - https://blogs.msdn.microsoft.com/rakkimk/2007/05/25/iis7-how-to-enable-the-detailed-error-messages-for-the-website-while-browsed-from-for-the-client-browsers/

Reproduce the issue and share the error message here. IIS generally gives out which module/configuration needs tweaking.

To answer your second question regarding start page, Select the website, click on "Default Document" and add the "index.html" page here and move it to top. This way, whenever the user accesses your website, he will see the index.html first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM