ASP.NET MVC 路由协助
我有一个 ASP.NET MVC 2 Web 应用程序,它应该从一个相当愚蠢的系统接收请求。相关系统期望它是一个 PHP 站点。它不是。我收到的请求的形式如下:
http://myIP/index.php?oa=val1&da=val1&ud=val1
我有一个带有方法的控制器
Index(string oa, string da, string ud)
,但我不知道如何将此请求路由到该控制器。我已经尝试过
routes.MapRoute(
"R",
"index.php/{oa}/{da}/{ud}",
new { controller = "Home", action = "Index" }
);
但没有成功。如果请求采用 Index.php/val1/val2/val3 格式,则它可以工作,但是当请求如上所示出现时,它会生成 404。
谢谢。
I have an ASP.NET MVC 2 web application which is supposed to receive a request from a rather stupid system. The system in question expects it to be a PHP site. It's not. The request I get is of the form:
http://myIP/index.php?oa=val1&da=val1&ud=val1
I have a controller with a method
Index(string oa, string da, string ud)
But I don't know how to get this request routed to this controller. I have tried
routes.MapRoute(
"R",
"index.php/{oa}/{da}/{ud}",
new { controller = "Home", action = "Index" }
);
But to no avail. It works if the request comes in the format Index.php/val1/val2/val3, but when the request comes as shown above, it generates a 404.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该路由不起作用,因为 QueryString 不是 RouteData 的一部分。最好将路由值与查询参数分开。
我将简单地映射index.php,然后访问控制器中的查询字符串。
The route doesn't work because the QueryString is not part of the RouteData. It's best to keep route values separate to query params.
I would simply map index.php and then access the query string in your controller.
我只是将路由映射到“php”页面。查询字符串参数不会转置为路线数据。
然后在控制器上执行操作
I would simply map the route to the "php" page. The query string parameters will not transpose into the route data.
and then for your action on the controller
您可以使用此路由:
并使用此方法:
You can use the this routing:
and use this method: