Click here to Skip to main content
11,496,146 members (452 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: ASP.NET
how to rewrite a url in asp.net?
Posted 22-Feb-12 2:05am
Comments
Rahul Rajat Singh at 22-Feb-12 7:09am
   
Could u please elaborate on what u want to do?
Mark Nischalke at 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
U don't Like Google?

rewrite a url in asp.net[^]
  Permalink  
Comments
Marcus Kramer at 22-Feb-12 11:32am
   
Please use full words here. You've been around long enough to know that text speak isn't acceptable.
Perhaps u could find HttpServerUtility.UrlEncode or similar functions useful
  Permalink  
Comments
Marcus Kramer at 22-Feb-12 11:32am
   
Please use full words here. You've been around long enough to know that text speak isn't acceptable.
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" />
  Permalink  
v2
Comments
Marcus Kramer at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 22 Feb 2012
Copyright © CodeProject, 1999-2015
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