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
The 'Request.ApplicationPath' will ensure that the full virtual path of your
application is passed to the LoadControl method and should solve the problem
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.