You can route as per MVC in ASP.NET.
In global.asax:
protected void Application_Start(object sender, EventArgs e)
{
//do stuff
RegisterRoutes(RouteTable.Routes);
//do stuff
?
public static void RegisterRoutes(RouteCollection routes)
{
routes.RouteExistingFiles = true;
routes.Add(new Route("{controller}/{action}",
new RouteValueDictionary { { "controller", "user" }, { "action", "home" } },
new RouteValueDictionary { { "controller", @"^(?!Resources)\w*$" }, { "action", "[a-zA-Z]+" } },// means that .htm path will go straight to the file, not thru our router
new MvcRouteHandler()));
}
Create your own route handler
public class CustomRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
//do stuff
string controller = RequestContext.RouteData.Values["controller"].ToString();
string methodName = RequestContext.RouteData.Values["action"].ToString();
//do stuff
}
}
public class RoutingHandler : UrlRoutingHandler
{
protected override void VerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext)
{
}
}
For the web.config:
<httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
***<add verb="*" path="UrlRouting.axd" validate="false" type="CustomHttpHandlerNamespaceAndClassName, CustomHttpHandlerNamespace" />***
</httpHandlers>
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>