Aspnetcore: Unable to start Kestrel: path base can only be configured using IApplicationBuilder.UsePathBase

Created on 4 Sep 2018  Â·  14Comments  Â·  Source: dotnet/aspnetcore

_From @JDGHHou on September 4, 2018 19:3_

My application runs fine in Visual Studio 2017 using the built-in IIS Express. However, when I deploy my code to IIS, suddenly I get the attached error.

I have found a couple of articles saying that I need to set my application URL to
"applicationUrl": "http://localhost/"
rather than
"applicationUrl": "http://localhost/{my application name}/"

But when I do that, my application tries to deploy to the webroot, and my application is stored in a folder elsewhere, so that doesn't work.

In all this, I am so confused as to what Microsoft's approach is. Why - if IIS Express works great at the press of a button - doesn't Microsoft just copy that exactly and apply it to IIS? I understand there may be more in-depth configuration a user may need to do, but that should be optional for users who need something more complex. Deploying something in IIS is almost always a complete living nightmare involving a million random undocumented settings. It is needlessly difficult and seems to default to the most random edge-case setup, rather than the most simple.

Anyway... Can someone please tell me how to make my application just deploy to IIS and work the same as it already does on other Microsoft products?

----------THIS IS THE ERROR MESSAGE --------------------

System.InvalidOperationException: 'A path base can only be configured using IApplicationBuilder.UsePathBase().'

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\JohnDunn\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.InvalidOperationException: A path base can only be configured using IApplicationBuilder.UsePathBase().
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.ParseAddress(String address, Boolean& https)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func2 createBinding) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication1 application, CancellationToken cancellationToken)

_Copied from original issue: aspnet/KestrelHttpServer#2882_

area-servers

Most helpful comment

@shirhatti Where do we have guidance on IIS deployments? https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x?

@JDGHHou This isn't a Kestrel specific issue but the error is caused by trying to set a path base via the applicationUrl configuration, which is not supported. Instead, you should be using the UsePathBase method as suggested in the error message, for example, keep the applicationUrl set to "http://localhost/" and use the following Configure method
c# public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UsePathBase("{my application name}"); app.Run(context => { return context.Response.WriteAsync("Hello World!"); }); }

All 14 comments

@shirhatti Where do we have guidance on IIS deployments? https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x?

@JDGHHou This isn't a Kestrel specific issue but the error is caused by trying to set a path base via the applicationUrl configuration, which is not supported. Instead, you should be using the UsePathBase method as suggested in the error message, for example, keep the applicationUrl set to "http://localhost/" and use the following Configure method
c# public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UsePathBase("{my application name}"); app.Run(context => { return context.Response.WriteAsync("Hello World!"); }); }

Yes, I've seen this code in some articles online. Have you tried to run it?

It doesn't work because context.Response doesn't have a method called WriteAsync. I can access context.Response.Body.WriteAsync, but this version of WriteAsync doesn't accept a string as parameter. It accepts some kind of write buffer or something.

Also, I don't want to send back a response of some random text.

I would like to route the path to my ASP .Net Core Razor page. I was hoping the default MVC routing I have set up in my Startup.cs file would handle that.

The current problem is that my pages load, but there is an AJAX post in the onload event of my window element on my index.cshtml. In that AJAX post I have a call to @Url.Action('{action}','{controller}') to create the post-to URL. When I inspect my generated page, the @Url.Action helper command has generated a blank string because - it seems - the Kestrel server crashed due to this error. So, the .Net Core Razor page that I am serving is not being processed properly.

Running in IIS shouldn't trigger this error unless you have some redundant configuration where you specify ASPNETCORE_URLS or similar containing "/applicationname". You should be able to remove that setting.

This error also occurs on startup, not per request, so your @Url.Action shouldn't ever be reached. Your Razor page issue may be something else.

@JDGHHou do you have any additional info on this so that we can investigate?

I basically just need to take an application that works fine when I launch
it in IIS Express and publish it to standalone IIS and have it run the same
way. It shouldn't be difficult. Microsoft has done an excellent job of
providing a quick and painless web host in IIS Express, and I don't
understand why the same code doesn't just work the same way in IIS.

On Mon, Sep 10, 2018, 1:24 PM Eilon Lipton notifications@github.com wrote:

@JDGHHou https://github.com/JDGHHou do you have any additional info on
this so that we can investigate?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aspnet/Home/issues/3495#issuecomment-420007470, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AOwWP5X8nyUWLl0SALjGnzF0betTrT3rks5uZqsFgaJpZM4WZrSA
.

Can pathbase be configured by command, similar to server.urls?

dotnet *.dll --server.urls "http://*:8080;https://*:8443;" --server.pathbase "/myapp"

@xdmushui not yet, that feature is tracked by https://github.com/dotnet/aspnetcore/issues/5898.

app.UsePathBase("/myapp");
When this code is used, swagger (Swashbuckle.AspNetCore) cannot resolve it.
Is there any solution?

@pranavkm any comment on Swashbuckle?

you can also get this issue when you run an API in VSCode and use the "env" section in the ".Net core Launch (web)" configuration incorrectly:
This will cause the error:

"env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS":"https://localhost:44362/api/"
            },

This will work:
Note that I only removed the "api/" from the URLS.

"env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS":"https://localhost:44362/"
            },

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

Was this page helpful?
0 / 5 - 0 ratings