AspNet4YouTop 10sDevelopers WorldForums
Home
About
ASPNet Books
ASPNet Sites
ASPNet Hosters
View Articles
Search Articles
Authors
View Forums
 
Quick Menus
HOME
About
AspNet4You Forums
Articles
Authors
Search
Articles Summary
Articles(RSSFeed)
AspNet Books
AspNet Sites
AspNet Hosters
 Top 10 ASP.NET Books 
Professional ASP.NET 1.1
Essential ASP.NET With Examples in C#
ASP.NET Unleashed
Programming Data Driven Web Applications with ASP.NET
Professional ASP.NET Web Services
Beginning ASP.NET 1.1 with Visual C# .NET 2003
Programming Microsoft ASP.NET
Beginning ASP.NET Databases Using VB.NET
ASP.NET Security
Developing Microsoft ASP.NET Server Controls and Components
More...
 Top 10 ASP.NET Hosters 
WebHost4Life
DiscountASP.NET
MaximumASP
Brinkster
ORCS Web
myhosting.com
ISQSolutions
ASPwebhosting.com, LLC
Active ISP
Aquest Hosting
More...
 Top 10 ASP.NET Sites 
Asp.Net
GotDotNet
4GuysFromRolla.com
123aspx.com
EggHeadCafe.com
CShrp.Net
.NET 247
DevelopersDex.com
Csharp-Corner.com
dotnetspider
More...
Search Articles
Google
ASPNET4YOU      
Category:   Search Type:   Match Type:  
The virtual path maps to another application, which is not allowed.
Author: Saha, ProdipPosted: 11/15/2005 8:07:23 PM

The virtual path maps to another application, which is not allowed.

You may receive this error when you try to load a user control dynamically. Suppose, you try to load a user control like the one below-

Control myUserControl= LoadControl("/Controls/UserControl.ascx");

You may be able to build the application if you are not trying access a page that is trying to load the control. When you run the above line, you will encounter the following error.

The virtual path '/Controls/UserControl.ascx' maps to another application, which is not allowed.

This occurs due to the fact that when loading your control, the full application virtual path is expected. If you fail to provide the full application path you will get the above error.

So, how do we solve the problem?

In order to overcome this problem you need to specify the full application path. You can do so by adding the following code:

Control myUserControl= LoadControl(Request.ApplicationPath +"/Controls/UserControl.ascx");

The 'Request.ApplicationPath' will ensure that the full virtual path of your application is passed to the LoadControl method and should solve the problem above.

One important thing to note that you may not be able to debug the error if you have some bad codes in the .ascx file. Suppose, you are trying to access a private property (by mistake) in <%=SomeClass.SomePrivateProperty %> this will result in compiler error.

Initially I had this item as a thread on the forum but it has become one of the popular search item. I thought it would be nice to share it as an article so that many people can access it easily.


Prodip K. Saha
The Architect of WWW.ASPNET4YOU.COM.

Terms and Conditions