Reputation: 63719
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:
ASP.NET Core Web Application (.NET Core)
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>
Hit F5 to run and localhost:6565/api/values
open up
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>
Open the IIS Manager GUI
web.config
is locatedBrowse 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:
LocalSystem
identity for the app pooldotnet --version
runs (i.e. is available on the PATH)In addition I've tried a few other things:
processPath
to variations of "%LAUNCHER_PATH%\bin\Debug\netcoreapp1.1\WebApplication1.dll
processPath
to point to dotnet.exe
or its locationWith 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?
Upvotes: 3
Views: 4004
Reputation: 339
I followed the Answer of @Jim Lowrey and follow some additional steps:
Upvotes: 0
Reputation: 412
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.
Upvotes: 0
Reputation: 109
I was able to get ASP.Net Core 2 to run behind IIS in development mode.
Create a new dotnet app. For example run 'dotnet new react -o my-new-app
' from the tutorial. Run npm install as directed.
Install AspNetCoreModule.
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.
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'.
Upvotes: 1
Reputation: 846
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.
Upvotes: 1
Reputation: 2733
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?
Upvotes: 0
Reputation: 16795
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).
Upvotes: 2