Loading a WebUserControl
I am trying to Load a WebUserControl that has a session id such as:
string loadURL = 开发者_如何学Go"/CPCLeadScrubExceptions.ascx?&SessionID=" + SessionId;
Control control = LoadControl(loadURL);
holder.Controls.Add(control);
When I do this I get the following error: "The virtual path '/CPCLeadScrubExceptions.ascx?&SessionID=a545a9e1-4085-419b-aff0-1a27a76d01e4' maps to another application, which is not allowed."
Well, the error is very clear. You're trying to load /CPCLeadScrubExceptions.ascx
, which maps to another application.
E.g. your app is http://mydomain.com/myapp/Something.aspx
so you can't access anything not under the /myapp/
path. You need to correct your path to be relative (first try without the '/' perhaps).
Edit: LoadControl
takes a control path, not a request URL with query string. ASP.NET uses the parameter to locate the control to load, it doesn't issue a request itself, therefore doesn't need the SessionID.
The path you're supplying is not a virtual path (they start with ~/
)
Plus the session id shouldn't be in the virtual path (you're not doing a request here), you could set it after you created the control like
control.SessionID = SessionId
If the control is in the same application you are calling it from, have you tried using:
string loadURL = "~/CPCLeadScrubExceptions.ascx?&SessionID=" + SessionId;
(Note the ~
sign.)
精彩评论