ASP.NET Virtual Path Maps To Another Application Which Is Not Allowed
Asked Answered
P

5

13

I have a website that was building without any issue on multiple servers.
But, when I copy/move it on the same machine from one folder to another folder: I started getting the error

The Virtual Path Maps To Another Application Which Is Not Allowed.

What am I doing wrong?

Peay answered 9/10, 2013 at 16:15 Comment(3)
What is the question?Peraza
You should separate out the answer and post it as an answer.Thimbleweed
I also saw this after switching branches in SVN; even though I rebuilt the solution, I also had to restart the website in IIS.Clubman
P
10

The source of this problem is that when one copies an ASP.NET Web Site to a new folder -- the properties setting associated with the solution "Virtual Path" is set to the folder name and not the root. The solution is to change the Virtual Path setting from the folder name to "/".

This can be found by right click the project and opening the properties dialog: Solution->Properties->Virtual Path-> Change to "/"

Peay answered 9/10, 2013 at 16:37 Comment(0)
A
1

This isn't why your error happened but it may be useful to someone researching the problem who ends up here.

If your web app is running as an application within another IIS site (set via the IIS administration tool) and is attempting to reach resources of the other site by means such as HttpResponse.Redirect, make sure the project isn't set to use a separate IIS in Visual Studio. If it is, it may be firing up inside a different IIS than the rest of the site.

Agrostology answered 18/4, 2018 at 19:17 Comment(0)
G
0

Additional check: Missing global.asax also causes the same error.

Grani answered 11/11, 2015 at 22:40 Comment(0)
E
0

If you are creating a new HttpContext and calling any external service, it also causes the same error.

Key is you should not create new HttpContext, change the existing context to your needs.

Estrous answered 5/8, 2020 at 5:34 Comment(0)
E
0

When attempting to compile the solution with MSBUILD 16 I would see the following error output by the 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]

It was failing on a Web Forms page that referenced a custom user control. My solution was mapped with a virtual path defined but this was by design and worked fine when the application is started directly from Visual Studio 2019 with IIS Express.

I needed it to compile the page for the current solution configuration without changing the mapping.

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

The following code was the problem

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

The fix was to prefix a tilde character '~' at the beginning of the user control path.

<%@ Register TagPrefix="uc1" TagName="TheUserControl" Src="~/DependencyDirectory/TheUserControl.ascx" %>
Elephantiasis answered 12/12, 2023 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.