开发者

Url Routing Rule is conflicting

I am implementing the URL Routing in my asp.net application, in that my some rules are conflicting. below is my some rules which is conflicting:

RouteTable.Routes.Add("QuestionSubject",
    new Route("questions/{subjectname}/{pageno}",
    new RouteValueDictionary { { "pageno", null } },
    new RouteValueDictionary { { "pageno", @"^[0-9]*$" } },
    new EventRouteHandler("~/questionsitemap/subject.aspx")));

RouteTable.Routes.Add("QuestionSubjectTopic",
    new Route("questions/{subjectname}/{topicname}/{pageno}",
    new RouteValueDictionary { { "pageno", null } },
    new RouteValueDictionary { { "pageno", @"^[0-9]*$" } },
    new EventRouteHandler("~/questionsitemap/topic.aspx")));

RouteTable.Routes.Add("QuestionGrade",
    new Route("questions/{gradename}/",
    new EventRouteHandler("~/questionsitemap/grade.aspx")));

RouteTable.Routes.Add("Questio开发者_开发知识库nSubjectGrade",
    new Route("questions/{gradename}/{subjectname}/",
    new EventRouteHandler("~/questionsitemap/grade.aspx")));

RouteTable.Routes.Add("QuestionSubjectTopicGrade",
    new Route("questions/{gradename}/{subjectname}/{topicname}/",
    new EventRouteHandler("~/questionsitemap/grade.aspx")));

In this when I am requesting to open the QuestionGrade rule it is calling the QuestionSubject because the rules are similar for both, same happened for others rule.

Please any one help me to find out the solutions for this.


You'll need to make them more specific since the routing engine can't distinguish between {subjectname} and {gradename}. Can you use something like the following, which adds /subject/ and /grade/ to your routes?

RouteTable.Routes.Add("QuestionSubject",
    new Route("questions/subject/{subjectname}/{pageno}",
    new RouteValueDictionary { { "pageno", null } },
    new RouteValueDictionary { { "pageno", @"^[0-9]*$" } },
    new EventRouteHandler("~/questionsitemap/subject.aspx")));

RouteTable.Routes.Add("QuestionGrade",
    new Route("questions/grade/{gradename}/",
    new EventRouteHandler("~/questionsitemap/grade.aspx")));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜