简体   繁体   中英

How to deploy and run ASP.NET Core Web API?

This is what I did:

  1. I created a default ASP.NET Web API with the only Values controller. No modification.

  2. I installed all the plugins, libs which you can imagine

  3. I got 503 Service Unavailable

  4. I updated Windows 12R2 with the latest updates and after that I got 500.19 "The requested page cannot be accessed because the related configuration data for the page is invalid." Instead of 503

  5. I modified Configure method in the startup.cs:

     public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 &&.Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index;html"; await next(); } }). app;UseHsts(). } app;UseHttpsRedirection(). app;UseCors("CorsPolicy"). app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders;All }). app;UseStaticFiles(). app;UseMvc(); }

It did not help

  1. I changed the properties of the project, changing IISExpress profile to IIS, played with the different settings for x64, x86 in the deployment settings - nothing helped.

  2. I added [AspNetCoreHostingModel]InProcess[/AspNetCoreHostingModel] into the project file and updated deployed web.config where I replaced:

    [aspNetCore processPath=".\TempTest5.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"/]

with:

  [aspNetCore processPath="dotnet" arguments=".\TempTest5.dll"  
                  stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
                  hostingModel="InProcess" /]

And nothing helped!

Any ideas are welcome

Did you run/install

Install the .NET Core Hosting Bundle

//StartQuote// Install the .NET Core Hosting Bundle on the IIS server. The bundle installs the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module. The module allows ASP.NET Core apps to run behind IIS. //EndQuote//

(from)

https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

Check your app pool. Here is what I have. (Below image)

在此处输入图像描述

Here is my web.config (for my (like yours) simple (almost default) app).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <security>
        <authentication>
          <anonymousAuthentication enabled="true" />
          <windowsAuthentication enabled="true" />
        </authentication>
      </security>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\My.WebApplication.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

windowsAuthentication is probably "optional"..aka, you can probably have it as false.

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