|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace CustomRoutes
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//Simple Custom Route with out any Constraints
routes.MapRoute(
"BlogWithoutConstraint",
"Archive/{entrydate}",
new { Controller = "Blog", action = "Archive", });
//Custom Route With Regular Expression Constraints
routes.MapRoute(
"Blog",
"Archive/{entrydate}",
new { Controller = "Blog", action = "Archive" }, new { entryDate = @"\d{2}-\d{2}-\d{4}" });
//Custom Route With HttpMethod Constraint
routes.MapRoute(
"HttpMethodConstraintRoute",
"Blog/Insert",
new { Controller = "Blog", action = "Insert" }, new { method = new HttpMethodConstraint("GET") });
//Custom Route Catch-All Routes
routes.MapRoute(
"CatchAllRoute",
"CatchAll/{*AllValues}",
new { Controller = "CatchAll", action = "Index" });
//Default Route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
//Uncomment Below Code When you want to Debug the Route
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been working as a Software Engineer on Microsoft .NET Technology.I have developed several web/desktop application build on .NET technology .My point of interest is Web Development,Desktop Development,Ajax,Json,Jquey,XML etc.I have completed Master of Computer Application in May-2011.I'm not happy unless I'm learning something new.