Try our conversational search powered by Generative AI!

Prevent UrlReWrite for a specific page type

Vote:
 

In the SDK , in the article for Friendly URL mentions that EPiServer CMS Furl rewrites all links in HTML when rendering it to the client. In most case, this is working fine. But I have a situation that I don't want the FURL do anything with my links, specially the src-attribute in the <img>.

Took a look at an article , written by Juwen Jin on the labs.episerver.com (http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/112064/112154/) and tried to doing that by listen to the event HttpRewritingToInternal

 static void module_HttpRewritingToInternal(object sender, UrlRewriteEventArgs e)

        {
string url = e.UrlContext.InternalUrl.Uri.AbsolutePath.ToLower();
if (url.EndsWith(".jpg") || url.EndsWith(".gif"))
{
//Do nothing with the link
		e.IsModified = true;
e.Cancel = true;
}
}
But it doesn't give any effect. The links still are rewritten and rebased to current pages path. 
Also tried with  HtmlRewriteUrl-event in RewritePipe for HtmlRewriteToExternal, but could neither solve the problem.
Anyone has any idéa? 
 
#19395
Apr 10, 2008 13:47
Vote:
 

I think you should be using HttpRewritingToExternal if you wan't to modify outgoing links.

#19398
Apr 10, 2008 14:15
Vote:
 
Also remember that server controls relocates your paths (link asp:image and img with runat=server).
#19399
Apr 10, 2008 14:18
Vote:
 

Actually, i had tried with HttpRewritingToExternal too but the result was the same.

my original link "/images/mypic.gif" was still being converted to "../../images/mypic.gif" (is this what you ment "server controls relocates your paths (link asp:image and img with runat=server)" ?)

If I set default provider for urlRewrite to EPiServerNullUrlRewriteProvider, the link "/images/mypic.gif" is maintained and it's exactly what I want!

Any other ideas?

 

Here is my code

public class UrlRewriteHandle : System.Web.IHttpModule
{
#region IHttpModule Members
static bool isURLHandlerInitialized = false;
public void Dispose()
{

}
public void Init(System.Web.HttpApplication context)
{
if (!isURLHandlerInitialized)
{
try
{
if (EPiServer.Web.FriendlyUrlRewriteProvider.IsFurlEnabled)
{
UrlRewriteModule.HttpRewriteInit += new EventHandler(UrlRewriteModule_HttpRewriteInit);
}
isURLHandlerInitialized = true;
}
catch
{
isURLHandlerInitialized = false;
}
}
}
static void UrlRewriteModule_HttpRewriteInit(object sender, UrlRewriteEventArgs e)
{
UrlRewriteModuleBase module = sender as UrlRewriteModuleBase;
if (module != null)
{
module.HttpRewritingToInternal += new EventHandler(module_HttpRewritingToInternal);
}
}
static void module_HttpRewritingToInternal(object sender, UrlRewriteEventArgs e)
{
string url = e.UrlContext.InternalUrl.Uri.AbsolutePath.ToLower();
if (url.EndsWith(".jpg") || url.EndsWith(".gif"))
{
e.Cancel = true;
}
}
#endregion
}

 

#19411
Apr 10, 2008 16:00
Vote:
 

Hiue,

Where do you use this link? Do you have runat=server on the component where you set the src attribute? If yes, have you tried using "~/images/mypic.gif"

#19438
Apr 10, 2008 18:04
Vote:
 
I have tested with "~/images/mypic.gif", and the link was converted to "../..//images/mypic.gif"  Cry
#19439
Apr 10, 2008 18:32
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.