将请求传输到 MVC 控制器或视图
我有一个 http 处理程序,它接收我的自定义扩展名 .page 的所有请求。这对于老式的 asp.net 来说工作得很好,我只需对所选的 aspx 文件执行 Server.Transfer 即可。 但是,我想将其移至 MVC,然后重新路由至控制器或视图。尽管我更喜欢控制器,但这并不重要。
对此主题的任何帮助表示赞赏。
谢谢!
I have an http handler which picks up all requests for my custom extension .page . This works fine with old fashion asp.net where I simply do a Server.Transfer to the aspx file of choice.
However, I would like to move this to MVC and instead reroute to either a Controller or a View. Doesn't matter which though I would prefer to a Controller.
Any help on this subject is appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将在
RouteTable.Routes
忽略的路由中添加一个新条目:这将允许
handler
作为物理资源进行调用。要从处理程序上下文重定向到
View
使用:I'd go about adding a new entry in the
RouteTable.Routes
ignored routes:This will allow the
handler
to be invoked as a physical resource.To redirect from the handler context to a
View
use:首先,您应该仅重定向到一个控制器,该控制器将选择要渲染的视图,但认为您不需要该自定义处理程序。尝试类似的方法(您应该以某种方式更改它以匹配您拥有的 url 格式)
如果这不起作用并且您确实想从处理程序重定向,请将 Xander 的忽略路由与
Afaik 结合起来,Server.Transfer 仅适用于 asp .net classic 所以你唯一的选择就是重定向。
Firstly, you should redirect only to a controller which will select the view to render but think that you don't need that custom handler. Try something like that (you should change it somehow to match the url format you have)
If that doesn't work and you really want to redirect from your handler, combine the ignoring route from Xander with
Afaik, Server.Transfer works only with asp.net classic so your only option is a redirect.