how to rewrite url string. in asp.net with c#.net.
A:
astander
2010-03-03 10:06:29
+4
A:
By googling dear friend :
Tip/Trick: Url Rewriting with ASP.NET
Mostafa
2010-03-03 10:08:06
what's goggling :P
James
2010-03-03 10:37:01
You got me (Googling) :P
Mostafa
2010-03-03 10:57:04
+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
2010-03-03 10:14:55