views:

412

answers:

4

how to rewrite url string. in asp.net with c#.net.

A: 

Have a look at

Tip/Trick: Url Rewriting with ASP.NET

from ScottGu's Blog

astander
+4  A: 

By googling dear friend :

Tip/Trick: Url Rewriting with ASP.NET

http://msdn.microsoft.com/en-us/library/ms972974.aspx

A Complete URL Rewriting Solution for ASP.NET 2.0

Mostafa
what's goggling :P
James
You got me (Googling) :P
Mostafa
+3  A: 

ASP.NET supports URL rewriting via System.Web.Routing, it is not just for ASP.NET MVC.

See How to: Use Routing with Web Forms on MSDN.

To have URL ~/foo handled by page ~/example/foo.aspx register the route in global.asax.cs

void Application_Start(object sender, EventArgs e)
{
    Route r = new Route("{Parameter}", new ExampleRouteHandler());
    Routes.Add(r);
}

And the route handler might look like this:

public class ExampleRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        string page = requestContext.RouteData.GetRequiredString("Parameter");

        if (page == "") {
            page = "default";
        }

        string @virtual = string.Format("~/example/{0}.aspx", page);

        return (Page)BuildManager.CreateInstanceFromVirtualPath(@virtual, typeof(Page));
    }
}
Lachlan Roche
A: 

Simple example step-by-step: Using UrlRewriter.Net

dario