I'm binding this control to a database which contains
~/Reports/Specimens/SpecimenReports.aspx?ReportName=DetailedSubmissionLog
When a user clicks on the item containing this url an error is generated
HttpException (0x80004005): '~/Reports/Specimens/SpecimenReports.aspx?ReportName=DetailedSubmissionLog' is not a valid virtual path.] System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options) +8855707 System.Web.VirtualPathUtility.ToAbsolute(String virtualPath) +12 Infragistics.Web.UI.NavigationControls.NavItem.get_ResolvedNavigateUrl() +110 Infragistics.Web.UI.NavigationControls.DataMenuRenderer.RenderItem(DataMenuItem item, DataMenuItemCollection items, HtmlTextWriter writer, Boolean isHorizontal) +1547 Infragistics.Web.UI.NavigationControls.DataMenuRenderer.Renderitems(DataMenuItemCollection items, HtmlTextWriter writer) +588 Infragistics.Web.UI.NavigationControls.DataMenuRenderer.RenderContents(HtmlTextWriter writer) +1611
What am I doing wrong?
I ran into this problem today when dynamically adding items to a WebDataMenu. The problem is actually due to the existence of a query string. Basically I had two page URLs like:
~/foo/page1.aspx
~/foo/page2.aspx?x=y
After I added these as menu items, the page crashed with the virtual path error for the second item. If I removed the querystring from the second item, both items worked fine.
Regardless, the easy workaround is to call Page.ResolveUrl on each url before passing it to the constructor of DataMenuItem().
Hi,
just check the URL that comes from the database, to make sure that it is correct. The MSDN documentation states that ToAbsolute() will throw HttpException when "A leading double period (..) is used to exit above the top directory."
I tried the following code:
protected internal string ResolvedNavigateUrl { get { if (NavigateUrl != null && NavigateUrl.Trim().IndexOf("~/") == 0) { return VirtualPathUtility.ToAbsolute(NavigateUrl); } return NavigateUrl; } }
this.NavigateUrl = "~/Reports/Specimens/SpecimenReports.aspx?ReportName=DetailedSubmissionLog"; string s = this.ResolvedNavigateUrl;
and s has the value "/Reports/Specimens/SpecimenReports.aspx?ReportName=DetailedSubmissionLog"
Thanks,
Lubomir