首页 新闻 会员 周边 捐助

关于路哟在。net3.5的应用我在项目中用到后就是找不到默认处理页面

0
悬赏园豆:20 [已解决问题] 解决于 2015-03-02 11:14

代码如下

  public class RouteHandler:IRouteHandler
    {
        public string virtualPath { get; private set; }

        public RouteHandler(string virtualPath)
        {
            this.virtualPath = virtualPath;
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var originalPage = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page)) as IHttpHandler;
            if (originalPage != null)
            {
                var routePage = originalPage as IRouteTablePage;
                if (routePage != null)
                {
                    routePage.RequestContext = requestContext;
                }   
            }
            return originalPage;
        }
    }

 

  public class RoutePage:Page,IRouteTablePage
    {
        #region IRouteTablePage 成员

        public RequestContext RequestContext
        {
            get;

            set;
        }

        #endregion

        public RouteValueDictionary RouteValues
        {
            get
            {
                if (RequestContext != null)
                {
                    return RequestContext.RouteData.Values;
                }
                return null;
            }
        }

        public object GetRouteValue(string key)
        {
            object resultvalue = null;
            if (RouteValues != null && RouteValues.Count > 0)
            {
                RouteValues.TryGetValue(key,out resultvalue);
            }
            return resultvalue;
        }
    }

 

interface IRouteTablePage
    {
        RequestContext RequestContext { get;set;}
    }

 

public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes); //RouteTable.Routes就是路由规则的集合,RouteTable就是系统定义的全局的静态路由表了

    }

    protected void Session_Start(object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {

    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {

    }

    protected void Application_Error(object sender, EventArgs e)
    {

    }

    protected void Session_End(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    }

    public void RegisterRoutes(RouteCollection routes)
    {
        routes.Add(new Route("news/category/{id}", new RouteHandler("Default.aspx")));
        routes.Add(new Route("news/{id}/{page}", new RouteHandler("Default.aspx")));
        routes.Add(new Route("news/{year}/{month}/{day}", new RouteHandler("Default.aspx")));
        routes.Add(new Route("search", new RouteHandler("Default.aspx")));
    }

}

 

就是找不到Default页面报如下错误

MingHao_Hu的主页 MingHao_Hu | 初学一级 | 园豆:8
提问于:2014-05-23 08:05
< >
分享
最佳答案
0

是路由写错了

MingHao_Hu | 初学一级 |园豆:8 | 2015-03-02 11:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册