首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ASP.NET MVC 路由时自定义IRouteHandler,该怎么解决

2013-09-05 
ASP.NET MVC 路由时自定义IRouteHandler自定义Route, RouteHandler, MVCHandler, 但是发现,程序区没有执行

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

热点排行