Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
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 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.
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 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.
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" />
  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 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


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