我正在我的asp.net应用程序中实现URL Routing,因为我的一些规则是冲突的。 下面是我的一些相互矛盾的规则:
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("QuestionSubjectGrade",
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")));
当我请求打开 QuestionGrade 规则时,它正在调用 QuestionSubject ,因为两者的规则相似,其他规则也是如此。
请任何人帮我找到解决方案。
答案 0 :(得分:1)
由于路由引擎无法区分{subjectname}
和{gradename}
,因此您需要使它们更具体。您可以使用以下内容,为您的路线添加/subject/
和/grade/
吗?
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")));