为什么我无法让 MvcHttpHandler 来处理我的 .mvc 请求?

发布于 2024-09-26 20:30:57 字数 807 浏览 2 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的故事 2024-10-03 20:30:58

这是一篇好文章,涵盖了不同的部署方案。以集成模式部署到 IIS 7 时不需要执行任何特定步骤。您不需要 default.aspx 文件,也不需要将 MvcHttpHandlerweb.config.mvc 扩展名关联起来代码>.如果您想要处理 IIS 7.0 中的无扩展路由和 IIS 6.0 中的 .mvc 扩展,您的路由可能如下所示。

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// This is for IIS 6.0
routes.MapRoute(
    "DefaultWithExtension",
    "{controller}.mvc/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

// The default extensionless route working with IIS 7.0 and higher
routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

仅 IIS 6.0 需要 .mvc 扩展名:

<httpHandlers>
    <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>

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 of MvcHttpHandler with the .mvc extension in your web.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.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// This is for IIS 6.0
routes.MapRoute(
    "DefaultWithExtension",
    "{controller}.mvc/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

// The default extensionless route working with IIS 7.0 and higher
routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

The .mvc extension is needed only for IIS 6.0:

<httpHandlers>
    <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
别理我 2024-10-03 20:30:58

结果我的托管公司并没有以集成模式运行我的应用程序,尽管他们告诉了我。解决了我的问题,但我也从达林那里得到了一些有用的提示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文