All routes we define is relied on default MvcRouteHandler. it connects routing system to MVC framework. Routing system also allow us to define our custom route handler by implementing IRouteHandler interface.
Public Class CustomRouteHandler Implements IRouteHandler Public Function GetHttpHandler(requestContext As System.Web.Routing.RequestContext) As System.Web.IHttpHandler Implements System.Web.Routing.IRouteHandler.GetHttpHandler Return New CustomHttpHandler End Function End Class Public Class CustomHttpHandler Implements IHttpHandler Public ReadOnly Property IsReusable As Boolean Implements System.Web.IHttpHandler.IsReusable Get Return False End Get End Property Public Sub ProcessRequest(context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest Dim ua As String = context.Request.UserAgent context.Response.Write("This request is made From :-" & ua) End Sub
The purpose of the IRouteHandler is to generate implementation of IHttpHandler that is responsible for generate the response. In MVC implementation of these interfaces controllers are found, action are invoked and views are rendered and result is written to response.This is just simple example. we have just written User agent information in response object. create a custom route handle means to take a responsibility to handle all functionality that is automatically handle by MvcRouteHandler. but it give you a incredible freedom to define you route handling system.We can register our custom route handler when we define routes.
routes.Add(New Route("{controller}/{action}", New CustomRouteHandler))
0 comments:
Post a Comment
Write your review about this post.