Using .NET Core 2.0, Windows 10, IIS Express.
While debugging my .NET Core web application, IIS Express launches a new browser window with the address localhost:7777/dashboard. Usually, I am able to view my web site at this point, but upon transferring my project over to a new machine with a fresh copy of Visual Studio Community 2017, the project returns a very strange error. The environment is identical to the environment on my last machine, so I see no reason why this error should occur. The error occurs because HttpContext.Request.Path is empty, even though I am accessing the path /dashboard in the URL. I noticed something very strange while looking into the error. HttpContext.Request.PathBase returns /dashboard even though HttpContext.Request.Path is returning an empty string.
The HttpContext object is accessed from the context argument passed within the line of code, app.Run(async (context) =>{}); located in Startup.cs.
Got same issue, why you have closed this ticket?
I closed it because I thought perhaps it was my own fault since I inherited the startup class with another startup class. But after some experimentation, I realized the problem persisted. I have a few other projects that work just fine, uses similar code base, same .NET Core version. I thought the problem was my own, but now I am reopening this because I can鈥檛 get request.path to populate in this one project no matter what I try.
Also, I鈥檝e come to realize that this issue persists on both dev machines, not just on the machine I transferred the project to.
I think I've narrowed down the issue at hand. All of my projects use Microsoft.AspNetCore NuGet packages for version 2.0.0, except for the project with this issue. That project uses NuGet packages 2.0.1. I can confirm that this issue only exists in Microsoft.AspNetCore NuGet packages version 2.0.1 because after installing & updating my project to version 2.0.0, everything works again, and Request.Path is populated again.
It worked for a few minutes after downgrading Microsoft.AspNetCore NuGet packages down from 2.0.1 to 2.0.0, and then it stopped working again. I haven't touched any code or closed the project, or done anything in any way to affect anything. I simply pressed play, stop, and play again, and it worked the first time, and now Request.Path is returning "/" instead of "/dashboard". Before it was working at all, though, Request.Path was returning an empty string, so now I'm getting even stranger behavior with Request.Path returning "/" and Request.PathBase returning "/dashboard".
Now I've narrowed it down even further. The first page request comes from dotnet.exe, then all other page requests are coming from a second instance of dotnet.exe. Very strange behavior!!!
Here is a log of page requests coming from my Startup.cs app.Run function. I am unable to break on any break points after my first request because all code is executed on a second dotnet.exe.
Websilk> Hosting environment: Development
Websilk> Content root path: C:\Projects\Websilk\Home\App
Websilk> Now listening on: http://localhost:26577
Websilk> Application started. Press Ctrl+C to shut down.
Websilk> --------------------------------------------
Websilk> 10:12:42 GET /
Websilk> END GET / 446 ms page
Websilk>
Websilk> Hosting environment: Development
Websilk> Content root path: C:\Projects\Websilk\Home\App
Websilk> Now listening on: http://localhost:12425
Websilk> Application started. Press Ctrl+C to shut down.
Websilk> --------------------------------------------
Websilk> 10:12:51 GET /
Websilk> END GET / 14 ms page
Websilk>
Websilk> --------------------------------------------
Websilk> 10:13:42 GET /
Websilk> END GET / 15 ms page
Websilk>
Websilk> --------------------------------------------
Websilk> 10:14:01 GET /
Websilk> END GET / 9 ms page
Websilk>
Websilk> --------------------------------------------
Websilk> 10:14:02 GET /
Websilk> END GET / 12 ms page
Websilk>
Websilk> --------------------------------------------
Websilk> 10:14:24 GET /
Websilk> END GET / 9 ms page
Websilk>
I figured out a solution. I simply deleted the hidden folder .vs and everything went back to normal :)
Thanks, I've just moved to use IIS instead IISExpress, that helps too.
Error still exists. Changing App URL in project properties corrupts .vs\configapplicationhost.config file. But I think it is VS2017 related bug, not .net core.
<application path="/" applicationPool="WebMonitoring AppPool">
<virtualDirectory path="/" physicalPath="C:\Repository\Monitoring\Sources\Application\WebMonitoring\WebMonitoring" />
<virtualDirectory path="/api/Cfg" physicalPath="C:\Repository\Monitoring\Sources\Application\WebMonitoring" />
<virtualDirectory path="/api" physicalPath="C:\Repository\Monitoring\Sources\Application" />
</application>
<application path="/api/Cfg/Register" applicationPool="Register AppPool">
<virtualDirectory path="/" physicalPath="C:\Repository\Monitoring\Sources\Application\WebMonitoring\WebMonitoring" />
</application>
Also seeing this issue even when running as a local site outside of visual studio. Path is null but PathBase is not. I did try to delete my .vs folder but that did not resolve it. I am using Microsoft.AspNetCore v 2.1.1
After further testing it appears that PathBase contains just the first part of the path after the host. Path contains any additional portion of the path after PathBase. For clarity, I've illustrated below;
Url: https://somesite.com/path1/path2/path3
PathBase: /path1
Path: /path2/path3
This is confusing - Path should include the entire path after the host.
I got into this state by changing the applicationUrl in launchSettings.json. Changing it back didn't fix it, however, until I deleted the hidden .vs folder.
Most helpful comment
After further testing it appears that
PathBasecontains just the first part of the path after the host.Pathcontains any additional portion of the path afterPathBase. For clarity, I've illustrated below;Url:
https://somesite.com/path1/path2/path3PathBase:
/path1Path:
/path2/path3This is confusing -
Pathshould include the entire path after the host.