Try our conversational search powered by Generative AI!

FriendlyUrlRewriteProvider and .aspx links

Vote:
 
In CMS 5: With or without frindly urls, you might have noticed that PageData.LinkURL returs a classic old school URL. Which means that if you take no special measures to convert it and don't render it as a href="LINK_HERE" you end up dealing with those URL:s, and, you want this old way of accessing a page to still work. However, if you have Friendly Urls turned on (default) and happen to access a page with /templates/MyPage.aspx?id=3&epslanguage=SV you get the StartPage (fallback mechanism). Ok, so they (EPiServer) have removed the possibility of loading CurrentPage through the id querystring param? Answer: no. The default mechanism in get_CurrentPageLink gets the id querystring param and loads the corresponding page through GetPage. Now the surprise. The id querystring param isn't there anymore. The very friendly rewrite engine rewrites this url to the much more user friendly /templates/MyPage.aspx?epslanguage=SV Ooops...where did my id querystring param go? Why did you remove it? And then, if you remove it, why the dependancy in get_CurrentPageLink. Maybe only intended for scenarios where you have friendly urls turned off? Ok, next experiment, we create another .aspx file on the root: Simple.aspx. No inheritance from EPiServer, just a VERY plain WebForm. Its sole content: <%=request.querystring%> We access it with /Simple.aspx?a=b&id=3 Resulting printout: a=b Ooops? So EPiServer takes the liberty to remove the id querystring param for all pages, not just PageBase pages. I can actually think of scenarios where the id attribute is used in a non EPiServer sense...sad to break that compatibility. My solution to this problem: MyFriendlyUrlRewriteProvider.cs namespace MyNamespace { class MyFriendlyUrlRewriteProvider: EPiServer.Web.FriendlyUrlRewriteProvider { public override bool ConvertToInternal(EPiServer.UrlBuilder url, out object internalObject) { internalObject = null; if (url.Path.EndsWith(".aspx")) return false; return base.ConvertToInternal(url, out internalObject); } } } web.config (in episerver/urlRewrite/providers)
#17711
Oct 05, 2007 15:38
Vote:
 
An easier solution, which is not involving any configuration at all, will be to add the following code in your Globala.asax.cs. protected void Application_Start(object sender, EventArgs e) { Global.UrlRewriteProvider.ConvertingToInternal += new EventHandler(UrlRewriteProvider_ConvertingToInternal); } void UrlRewriteProvider_ConvertingToInternal(object sender, UrlRewriteEventArgs e) { e.Cancel = e.Url.Path.EndsWith(".aspx"); } Regards, Tibi
#18548
Nov 14, 2007 13:55
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.