简体   繁体   English

无法删除虚拟目录(.NET MVC 5 + IIS Express)

[英]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.在尝试将http://localhost:12345重定向到http://localhost:12345/user/login时,我创建了一个虚拟目录,现在我意识到它只是重新映射http://localhost:12345以显示为http:// /localhost:12345/user/login而不是去那个视图本身。

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).所以我添加了一个虚拟目录,但在任何地方都找不到它来删除它(IISExpress/config 文件、.NET 项目文件、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.我的理解是单击“创建虚拟目录”会在 IISExpress/config/redirection.xml 文件中添加一个条目,但我在其中看不到任何虚拟目录的内容,更不用说我创建的那个了。 I also tried restoring all the config xml files in IISExpress/config/ from a backup but to no avail.我还尝试从备份中恢复 IISExpress/config/ 中的所有配置 xml 文件,但无济于事。 I also searched the entire solution for "/user/login".. I can't find where this is set anywhere.我还搜索了“/user/login”的整个解决方案。我找不到任何地方的设置。

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).问题是我必须使用 URL http://localhost:12345/user/login/user/login才能进入 /user/login 的登录页面(使用属性路由)。 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.我从 RouteConfig 和使用它的控制器中删除了属性路由(并取消删除了那些控制器/区域的 AreaRegistration.cs 文件),现在我只能通过前缀 /user/login 来访问 /User/Login,所以问题不是属性路由。 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.我在浏览到根http://localhost:12345时收到此信息 - 未找到视图“/user/login”或其主视图,或者没有视图引擎支持搜索的位置。 The following locations were searched: /user/login.搜索了以下位置:/user/login。 So it's definitely interpreting localhost:12345/ as localhost:12345/user/login/...所以它肯定将 localhost:12345/ 解释为 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.我在带有完整 IIS 的 Windows Server 2016 上,但没有理由使用 IIS 而不是 IIS Express。 It's set to use IIS Express in Properties of the project.它设置为在项目的属性中使用 IIS Express。

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.编辑:该问题通过 TFS 转移到全新安装的 Windows 和 VS,因此问题似乎出在 .NET 项目本身。 Also, the issue is only with the /user/login page, in another Area, the pages load as expected without needing /user/login prefix.此外,问题仅在于 /user/login 页面,在另一个区域中,页面按预期加载,不需要 /user/login 前缀。 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.但同样,我在 RouteConfig 或 WebConfig 或其他任何地方都没有看到任何异常......无论如何,我回滚了变更集并且一切都很好,所以这个问题在技术上已经“解决”了,但我仍然想知道是什么导致了新变更集中的“虚拟目录式”行为。

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).在 Visual Studio 解决方案(不是项目)的 .vs 子目录中找到 applicationhost.config。

<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> .对我来说,我创建的虚拟目录在这里显示为一个新的<application>标记,而不是<virtualDirectory> It seems like removing the extra application tag worked.似乎删除额外的应用程序标签有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM