Curtis White
Curtis White

Reputation: 6353

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

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?

Upvotes: 13

Views: 18902

Answers (5)

nimblebit
nimblebit

Reputation: 559

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" %>

Upvotes: 0

Asfar Irshad
Asfar Irshad

Reputation: 765

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.

Upvotes: 0

Otis
Otis

Reputation: 1072

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.

Upvotes: 1

patelsan
patelsan

Reputation: 478

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

Upvotes: 0

Curtis White
Curtis White

Reputation: 6353

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 "/"

Upvotes: 10

Related Questions