ASP.NET 虚拟路径映射到另一个不允许的应用程序

问题描述 投票:0回答:5

我有一个网站在多个服务器上构建时没有任何问题。
但是,当我在同一台计算机上将其从一个文件夹复制/移动到另一个文件夹时:我开始收到错误

虚拟路径映射到另一个不允许的应用程序。

我做错了什么?

asp.net iis hosting
5个回答
10
投票

此问题的根源在于,当将 ASP.NET 网站复制到新文件夹时,与解决方案“虚拟路径”关联的属性设置将设置为文件夹名称而不是根目录。解决方案是将虚拟路径设置从文件夹名称更改为“/”。

可以通过右键单击项目并打开属性对话框找到:解决方案->属性->虚拟路径->更改为“/”


1
投票

这不是您发生错误的原因,但它可能对研究问题并最终出现在这里的人有用。

如果您的 Web 应用程序作为另一个 IIS 站点中的应用程序运行(通过 IIS 管理工具设置),并尝试通过 HttpResponse.Redirect 等方式访问其他站点的资源,请确保该项目未设置为使用Visual Studio 中的单独 IIS。如果是,则它可能在与站点其他部分不同的 IIS 中启动。


0
投票

额外检查:缺少 global.asax 也会导致相同的错误。


0
投票

如果您正在创建一个新的 HttpContext 并调用任何外部 服务,也会导致同样的错误。

关键是你不应该创建新的 HttpContext,而应该更改现有的 满足您的需求。


0
投票

尝试使用 MSBUILD 16 编译解决方案时,我会看到 ASPNETCOMPILER 输出以下错误。

"C:\MyProject\solution.metaproj" (default target) (22) ->
(Build target) -> 
  /localhost_12345/WebPage.aspx(1): error ASPPARSE: The virtual path '/UserControls/TheUserControl.ascx' maps to another application, which is not allowed. [C:\MyProject\solution.metaproj]
  /localhost_12345/WebPage.aspx(2): error ASPPARSE: Unknown server tag 'uc1:TheUserControl'. [C:\MyProject\solution.metaproj]

引用自定义用户控件的 Web 表单页面失败。 我的解决方案是使用定义的虚拟路径进行映射的,但这是所需的行为,因此我需要它来编译当前配置的页面而不进行更改。

Project("{guid}") = "applicationname", "applicationname", "{guid}"
    ProjectSection(WebsiteProperties) = preProject

        Debug.AspNetCompiler.VirtualPath = "/localhost_12345"
        Debug.AspNetCompiler.PhysicalPath = "Subdirectory\"
        Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_12345\"
        Release.AspNetCompiler.VirtualPath = "/localhost_12345"
        Release.AspNetCompiler.PhysicalPath = "Subdirectory\"
        Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_12345\"       
        SlnRelativePath = "Subdirectory\"

    EndProjectSection
EndProject

以下代码就是问题所在

<%@ Register TagPrefix="uc1" TagName="TheUserControl" Src="/DependencyDirectory/TheUserControl.ascx" %>

修复方法是在用户控制路径的开头添加波浪号字符 '~'

<%@ Register TagPrefix="uc1" TagName="TheUserControl" Src="~/DependencyDirectory/TheUserControl.ascx" %>
© www.soinside.com 2019 - 2024. All rights reserved.