具有两个变量的 URL 路由不起作用
ASP.net MVC url 路由有问题。我已经创建了这条路由(它是我的 RegisterRoutes 方法中的第一个路由:
routes.MapRoute(
"Activate",
"Account/Activate/{username}/{key}",
new { controller = "Account", action = "Activate", username = "", key = "" },
new { username = @"([a-z0-9\.-]+)", key = @"([a-z0-9\.-]+)" }
);
但是当我尝试像这样访问 tu URL 时:
http://localhost:63779/acount/activate/test/hLMqWJrwp1dK5xTqbGkP5kzUNQ4
它返回 404 错误
(使用 UrlParameter.Optional 我得到了相同的结果)
a have a problem with ASP.net MVC url routing. I have created this route (it is first route in my RegisterRoutes method:
routes.MapRoute(
"Activate",
"Account/Activate/{username}/{key}",
new { controller = "Account", action = "Activate", username = "", key = "" },
new { username = @"([a-z0-9\.-]+)", key = @"([a-z0-9\.-]+)" }
);
but when i try to go tu URL like this:
http://localhost:63779/acount/activate/test/hLMqWJrwp1dK5xTqbGkP5kzUNQ4
it returns 404 error
(with UrlParameter.Optional I've got the same result)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是你的正则表达式不正确。使用以下命令:
显示的正则表达式将匹配包含任何单词字符(\w 与 [A-Za-z0-9_] 相同)或点的字符串,其中不包含空格或其他字符。
更新
测试路线并将其复制到我的答案中后,我忘记将控制器值更改为“帐户”。我已经更新了上面的路线。
The problem is that your regular expression is incorrect. Use the following:
The regex shown will match a string containing any word character (\w is the same as [A-Za-z0-9_]) or a dot, which has no spaces or other characters.
UPDATE
After testing the route and copying it into my answer, I forgot to change the controller value to "Account". I have updated the route above.