开发者

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

Is this possible:

I have web application with usercontrols in the following directory : C:\Users\Visual Studio 2010\WebSites\MS\Controls

I have another web application on my machine with the following location : C:\Users\Visual Studio 2010\WebSites\TestSite

Can TestSite load the userwebcontrol from different directory.

I tried the following in 开发者_如何转开发TestSite:

myUserControl = (UserControl)LoadControl("../WebSites/CMS/Controls/test.ascx");

But i get the error: The virtual path '/WebSites/MS/Controls/test.ascx' maps to another application, which is not allowed.

Tried using ~ at the beginning but comes up with The file '/TestSite/MS/Controls/Editor.ascx' does not exist.

Can this be done?


UserControl.LoadControls(path) uses a VIRTUAL PATH, not a file-system path. If your VisualStudio project's root is C:\Users\Visual Studio 2010\WebSites\TestSite, then that is as low as that application will be able to reference (using the '~').


In my case, it was a wrong value for Layout in the cshtml file. It should be

Layout = "~/Views/Shared/_MySiteMaster.cshtml"

instead of

Layout = "/Views/Shared/_MySiteMaster.cshtml" 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜