为什么我无法让 MvcHttpHandler 来处理我的 .mvc 请求?
我有一个使用 Asp.Net 3.5 和 MVC 1 的项目。
一切都在我的本地 IIS 上完美运行,但在我将其部署到托管服务器后就不行了。
Web 服务器是 IIS7,并激活了集成管道(根据托管公司的说法)。
当我转到网站的根目录 www.site.com 时,default.aspx 会重定向到控制器,如下所示:
public void Page_Load(object sender, System.EventArgs e)
{
字符串originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath + "Controller.mvc/Action", false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
这
有效并且显示了正确的视图。但是,当我在浏览器中输入相同的地址 www.site.com/Controller.mvc/Action 时,我收到 404.0 错误。所以看来 MvccHttpHandler 没有正确调用(?)。
web.config 设置为 runAllManagedModulesForAllRequests="true",并且 MvcHttpHandler 配置为处理 .mvc 扩展。
我做错了什么,有什么想法吗?
I have a project using Asp.Net 3.5 and MVC 1.
Everything runs perfectly on my local IIS, but not after I deployed it to the hosted server.
The web server is IIS7 with integrated pipeline activated (according to the hosting company).
When I go to the root of the web site, www.site.com, the default.aspx makes a redirect to a controller like so:
public void Page_Load(object sender, System.EventArgs e)
{
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath + "Controller.mvc/Action", false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
This works and the correct view is shown. However, when I type the same address in the browser, www.site.com/Controller.mvc/Action I get a 404.0 error. So it seems the MvccHttpHandler is not invoked correctly(?).
The web.config is set up with runAllManagedModulesForAllRequests="true", and a MvcHttpHandler is configured to handle .mvc extensions.
What am I doing wrong, any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一篇好文章,涵盖了不同的部署方案。以集成模式部署到 IIS 7 时不需要执行任何特定步骤。您不需要
default.aspx
文件,也不需要将MvcHttpHandler
与web.config.mvc
扩展名关联起来代码>.如果您想要处理 IIS 7.0 中的无扩展路由和 IIS 6.0 中的.mvc
扩展,您的路由可能如下所示。仅 IIS 6.0 需要
.mvc
扩展名:Here's a good article which covers different deployment scenarios. There are no particular steps required when deploying to IIS 7 in integrated mode. You don't need a
default.aspx
file and association ofMvcHttpHandler
with the.mvc
extension in yourweb.config
. Here's how your routes might look like if you want to handle both extensionless routes in IIS 7.0 and the.mvc
extension in IIS 6.0.The
.mvc
extension is needed only for IIS 6.0:结果我的托管公司并没有以集成模式运行我的应用程序,尽管他们告诉了我。解决了我的问题,但我也从达林那里得到了一些有用的提示。
Turned out my hosting company did not run my application in integrated mode, even though they told me. Solved my problems, but I also got a few helpful tips from Darin.