读书人

ASP.NET MVC 路由时自定义IRouteHandl

发布时间: 2013-09-05 16:02:07 作者: rapoo

ASP.NET MVC 路由时自定义IRouteHandler
自定义Route, RouteHandler, MVCHandler, 但是发现,程序区没有执行自定义的IHttpHanlder中的ProcessRequest方法, 为什么呢?

RouteValueDictionary defaults = new RouteValueDictionary();
RouteValueDictionary constraints = new RouteValueDictionary();
RouteValueDictionary tokens = new RouteValueDictionary();

defaults.Add("controller", "home");
defaults.Add("action", "index");
defaults.Add("data", string.Empty);
constraints.Add("data", @"[a-zA-Z0-9\-]*");
tokens.Add("namespaces", new[] { Namespace });
tokens.Add("pageId", 0);

routes.Add(new Route("", defaults, constraints, tokens, new MyRouteHandler()));

public class MyRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new MyHttpHandler(requestContext);
}
}

public class MyHttpHandler : MvcHandler
{
public MyHttpHandler(RequestContext requestContext) : base(requestContext)
{
}

protected override void ProcessRequest(HttpContextBase httpContext)
{
int i = 1;
int j = i + 1;
//IController controller = new Web.Controllers.HomeController();
//(controller as Controller).ActionInvoker = new MyActionInvoker();
//controller.Execute(RequestContext);
}


}


[解决办法]
web.config注册了吗
[解决办法]
web.config中的system.web节点下httpHandlers节点中添加自定义的handler

读书人网 >asp.net

热点推荐