简体   繁体   中英

Can't remove virtual directory (.NET MVC 5 + IIS Express)

In trying to have http://localhost:12345 redirect to http://localhost:12345/user/login , I created a virtual directory, which I now realize just remaps http://localhost:12345 to show as http://localhost:12345/user/login rather than going to that view itself.

So I added a virtual directory, but can't find it anywhere to remove it (IISExpress/config files, the .NET project files, Properties menu for the project in VS). My understanding is that clicking "Create Virtual Directory" adds an entry to the IISExpress/config/redirection.xml file, but I don't see anything in there for a virtual directory, much less the one I created. I also tried restoring all the config xml files in IISExpress/config/ from a backup but to no avail. I also searched the entire solution for "/user/login".. I can't find where this is set anywhere.

The issue is that I have to use the URL http://localhost:12345/user/login/user/login to get to the login page at /user/login (using Attribute Routing). I removed Attribute Routing from RouteConfig and the controllers where I was using it (and undeleted the AreaRegistration.cs files for those controllers/areas), and now I can only reach /User/Login by prefixing with /user/login, so the issue is NOT Attribute Routing. It has to be that Virtual Directory.

I get this when browsing to the root http://localhost:12345 - The view '/user/login' or its master was not found or no view engine supports the searched locations. The following locations were searched: /user/login. So it's definitely interpreting localhost:12345/ as localhost:12345/user/login/...

I am on Windows Server 2016 with the full IIS, but there's no reason it would be using IIS rather than IIS Express. It's set to use IIS Express in Properties of the project.

EDIT: The issue carried over to a fresh install of Windows and VS via TFS, so it seems like the the issue is in the .NET project itself. Also, the issue is only with the /user/login page, in another Area, the pages load as expected without needing /user/login prefix. But again, I don't see anything anomalous in RouteConfig or WebConfig or anywhere else... In any event, I rolled back the changeset and all is well, so the issue is technically "solved", but I'd still like to know what is causing the "virtual directory-esque" behavior in the newer changeset.

Right click on the virtual directory and select "Convert to Application".

Then right click on the application and select "Remove".

Find applicationhost.config in the .vs subdirectory of the Visual Studio solution (not project).

<site name="ProjectName" id="3">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\nn\source\repos\Solution\ProjectName" />
    </application>
    <application path="/user/login" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\nn\source\repos\Solution\ProjectName" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:58262:localhost" />
        <binding protocol="https" bindingInformation="*:44316:localhost" />
    </bindings>
</site>

For me, the virtual directory I had created appeared as a new <application> tag here, not a <virtualDirectory> . It seems like removing the extra application tag worked.

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