2010-10-08 26 views
0

我有一个项目使用Asp.Net 3.5和MVC 1.为什么我无法获得MvcHttpHandler来处理我的.mvc请求?

一切运行完美我的本地IIS,但不是我将它部署到托管服务器后。

Web服务器是IIS7集成管道激活(根据托管公司)。

当我去到网站,www.site.com的根,在Default.aspx的使重定向到一个控制器,像这样:

公共无效的Page_Load(对象发件人,发送System.EventArgs)
{
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);
}

这工作正常并显示正确的视图。但是,当我在浏览器中输入相同的地址时,www.site.com/Controller.mvc/Action,我得到一个404.0错误。所以看起来MvccHttpHandler没有被正确调用(?)。

web.config使用runAllManagedModulesForAllRequests =“true”进行设置,并且MvcHttpHandler被配置为处理.mvc扩展名。

我做错了什么,有什么想法?

回答

1

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

3

这是一个good article,它涵盖了不同的部署方案。在集成模式下部署到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 } 
); 

.mvc扩展,只需要对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> 
+0

谢谢你的建议。但是,我的问题仍然存在。无论我是否使用mvc-extensions,对我的控制器的任何请求都会给我一个404.0错误。唯一能让它工作的方法是通过default.aspx手动处理请求,这使我相信问题出在MvcHttpHandler上。 – 2010-10-10 10:26:55

相关问题