Click here to Skip to main content
13,004,215 members (78,499 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
how to rewrite a url in asp.net?
Posted 22-Feb-12 1:05am
Comments
Rahul Rajat Singh 22-Feb-12 7:09am
   
Could u please elaborate on what u want to do?
Mark Nischalke 22-Feb-12 7:10am
   
You've got to do better than this. Try to write the question as if we have no idea what you are trying to accomplish
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

U don't Like Google?

rewrite a url in asp.net[^]
  Permalink  
Comments
Marcus Kramer 22-Feb-12 11:32am
   
Please use full words here. You've been around long enough to know that text speak isn't acceptable.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Perhaps u could find HttpServerUtility.UrlEncode or similar functions useful
  Permalink  
Comments
Marcus Kramer 22-Feb-12 11:32am
   
Please use full words here. You've been around long enough to know that text speak isn't acceptable.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

FormRewriterControlAdapter.cs
 
public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter
{
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        base.Render(new RewriteFormHtmlTextWriter(writer));
    }
}
public class RewriteFormHtmlTextWriter : HtmlTextWriter
{
    public RewriteFormHtmlTextWriter(HtmlTextWriter writer)
        : base(writer)
    {
        this.InnerWriter = writer.InnerWriter;
    }
    public override void WriteAttribute(string name, string value, bool fEncode)
    {
        if (name == "action")
        {
            HttpContext Context;
            Context = HttpContext.Current;
            if (Context.Items["ActionAlreadyWritten"] == null)
            {
                value = Context.Request.RawUrl;
                Context.Items["ActionAlreadyWritten"] = true;
            }
        }
        base.WriteAttribute(name, value, fEncode);
    }
}

web.config
<rewriter>
<rewrite url="/WebSite3/Product/(.+)" to="/WebSite3/Product.aspx?category=$1" />
<!--<rewrite url="/WebSite3/Product/(.+).aspx" to="/WebSite3/Product.aspx?category=$1"/>-->
<!--<rewrite url="/WebSite3/Product/books.aspx" to="/WebSite3/Product.aspx?category=books" />-->
</rewriter>


in App_Browser folder
Form.Browser file
<browsers>
   <browser refid="Default">
      <controladapters>
         <adapter controltype="System.Web.UI.HtmlControls.HtmlForm">
	   adapterType="FormRewriterControlAdapter" />
         </adapter>
      </controladapters>
   </browser>
</browsers>
  Permalink  
v2
Comments
Marcus Kramer 22-Feb-12 11:34am
   
Just cleaned up the pre tags for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 22 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100