3

I'm trying to host an ASP.NET Core application in IIS on my local machine, and I'm getting a 502.5 error. My question is different from "ASP.NET Core 1.0 on IIS error 502.5" because I'm not publishing my app, but (for testing purposes) trying to have IIS (not express) on my dev machine serve up the app.

To reproduce:

  1. Open VS2017
  2. Create a new ASP.NET Core Web Application (.NET Core)
  3. Choose the "Web API" template and target "ASP.NET Core 1.1" (no authentication)

    Your Main looks like this now:

    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseApplicationInsights()
            .Build();
    
        host.Run();
    }
    

    Your csproj looks like this:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <Folder Include="wwwroot\" />
      </ItemGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
      </ItemGroup>
      <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
      </ItemGroup>
    
    </Project>
    
  4. Hit F5 to run and localhost:6565/api/values open up

  5. Add a "Web Configuration File" to the root of the project
  6. Uncomment the system.webServer section looking like this:

    <system.webServer>
        <handlers>
          <remove name="aspNetCore"/>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
        </handlers>
        <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
    
  7. Open the IIS Manager GUI

  8. Choose "Add Website", pick a name and a port, set the path to the folder where the web.config is located
  9. As per Microsoft's instructions set the Application Pool's ".NET CLR version" to "No Managed Code"
  10. Browse to your new application, e.g. http://localhost:8089/api/values

    Result: HTTP Error 502.5 - Process Failure
    Expected: same result as in step 4.

I've tried to exclude all causes mentioned in the top answer to the other question:

  • Set LocalSystem identity for the app pool
  • Check on the console if dotnet --version runs (i.e. is available on the PATH)

In addition I've tried a few other things:

  • Set processPath to variations of "%LAUNCHER_PATH%\bin\Debug\netcoreapp1.1\WebApplication1.dll
  • Set processPath to point to dotnet.exe or its location
  • Re-read the docs to distill a way to do this.

With ASP.NET MVC applications on the .NET Framework you could just spin up a new Website in full IIS that points to the MVC project's folder and it would "just work".

What do you need to do to get this to work with ASP.NET Core? Is it even possible to get this flow working without publishing?

Jeroen
  • 60,696
  • 40
  • 206
  • 339
  • Possible duplicate of [ASP.NET Core 1.0 on IIS error 502.5](https://stackoverflow.com/questions/38624453/asp-net-core-1-0-on-iis-error-502-5) – Pranav Patel Jun 15 '17 at 12:50
  • @PranavPatel I've explained already in my question why it is different, no? I want to skip the "Publish" step, just like you could do with ASP.NET 4.6 MVC applications. – Jeroen Jun 15 '17 at 13:07

5 Answers5

2

What do you need to do to get this to work with ASP.NET Core

Execute all required instructions, not only section you like. You should do publishing.

Is it even possible to get this flow working without publishing?

No.

During publishing your project is compiled and your web.config is modified to run compiled app (without SDK).

Dmitry
  • 16,110
  • 4
  • 61
  • 73
1

You can use the new feature of Visual Studio 15.3 and newer called Development time IIS support.

Please see the related issue and the blog post for the new feature.

Arman
  • 796
  • 6
  • 12
1

I was able to get ASP.Net Core 2 to run behind IIS in development mode.

  1. Create a new dotnet app. For example run 'dotnet new react -o my-new-app' from the tutorial. Run npm install as directed.

  2. Install AspNetCoreModule.

  3. In IIS create a new site with no managed code and set the App Pool to run under LocalSystem. It will need this to write to C:\WINDOWS\system32\config\systemprofile. Set the physical path to the directory created from step 1.

  4. Put the following web.config in the directory from step 1.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <!--
        Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
      -->
      <system.webServer>
        <handlers>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe"
                    arguments="run --project C:\<your-path-to>\my-new-app" 
                    stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
            <environmentVariables>
              <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
            </environmentVariables>
        </aspNetCore>
      </system.webServer>
    </configuration>
    

From there AspNetCoreModule orchestrates the interaction between IIS and dotnet.exe and the reverse proxy is set up. As a bonus all the webpack compiling, bundling and hot reloading worked just as they did with 'dotnet run'.

Syscall
  • 19,327
  • 10
  • 37
  • 52
Jim Lowrey
  • 109
  • 8
0

As @Dmitry is saying, I'm not sure you can plug IIS on an 'unpublished' folder, but there is something more, as stated in https://learn.microsoft.com/en-us/aspnet/core/publishing/iis, you need a module to enable IIS to plug itself on an ASP.NET Core module which is called ".NET Core Windows Server Hosting", have you installed it?

Daboul
  • 2,635
  • 1
  • 16
  • 29
0

I'm not sure if anything has changed since the previous answers as I've only just started using ASP.NET Core, but see @Sнаđошƒаӽ's answer here. It just worked for me on ASP.NET Core 3.1.

Note that changes in cshtml files won't be reflected without building or publishing. To get runtime compilation of Razor files so that changes appear after just a page refresh, use Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation as explained here.

jsabrooke
  • 405
  • 7
  • 12