IIS 6上的ASP.NET MVC - 通配符映射 - 传入请求与任何路由都不匹配

时间:2020-12-28 03:34:40

I have been trying to set up my Beta 1 MVC app on IIS 6 and cannot get it to run correctly. I have added a Wildcard mapping to the .net isapi DLL as suggested in other blog posts but get the following error when I access the root of the website:

我一直在尝试在IIS 6上设置我的Beta 1 MVC应用程序,但无法正常运行。我已经按照其他博客文章的建议添加了.net isapi DLL的通配符映射,但是当我访问网站的根目录时出现以下错误:

The incoming request does not match any route.
..
[HttpException (0x80004005): The incoming request does not match any route.]
   System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) +147
   System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) +36
   System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +4
   HCD.Intranet.Web.Default.Page_Load(Object sender, EventArgs e) +81
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

I am using the Default.aspx page supplied in the MVC template application that rewrites access to the root of the website properly.

我正在使用MVC模板应用程序中提供的Default.aspx页面,该页面正确地重写对网站根目录的访问。

public partial class Default : Page
{
    public void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext.Current.RewritePath(Request.ApplicationPath);
        IHttpHandler httpHandler = new MvcHttpHandler();
        httpHandler.ProcessRequest(HttpContext.Current);
    }
}

If I try and access a route within the application, such as /Project, I get the standard IIS 404 error page, not the .net error page.

如果我尝试访问应用程序中的路径,例如/ Project,我会得到标准的IIS 404错误页面,而不是.net错误页面。

I tried adding the following line to my Web.config httpHandlers section:

我尝试将以下行添加到我的Web.config httpHandlers部分:

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

This gave me a different error - the .net 404 error page.

这给了我一个不同的错误 - .net 404错误页面。

I added the following to my Global.asax, which did nothing:

我将以下内容添加到我的Global.asax中,它没有做任何事情:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Context.Request.FilePath.Equals("/"))
        Context.RewritePath("Default.aspx");
}

I am using the following route configuration (uses the restful routing supplied by the MvcContrib project):

我正在使用以下路由配置(使用MvcContrib项目提供的restful路由):

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
SimplyRestfulRouteHandler.BuildRoutes(routes);
routes.MapRoute(
"Default", 
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);

Any suggestions would be grealy received as I've exhausted all options for the time I have right now.

任何建议都会得到很好的收获,因为我已经用尽了现在的所有选项。

Many thanks.

非常感谢。

3 个解决方案

#1


8  

OK, got it working.

好的,搞定了。

The problem was that I was using msbuild automation to package up the files that I needed to deploy, and I was missing global.asax.

问题是我使用msbuild自动化来打包我需要部署的文件,而我缺少global.asax。

So it looks like if global.asax is not deployed to the site then none of the routes get hooked up. This means that hitting the website root correctly results in the error 'The incoming request does not match any route.', and any other requests no longer get routed through to your controller classes, so result in a 404.

因此,如果没有将global.asax部署到站点,那么没有任何路由被连接起来。这意味着正确访问网站根目录会导致错误“传入的请求与任何路由都不匹配。”,并且任何其他请求不再被路由到您的控制器类,因此导致404。

HTH.

HTH。

#2


18  

Here's what I did to get extensionless URLs working with IIS 6 and ASP.NET MVC Beta 1.

以下是我使用IIS 6和ASP.NET MVC Beta 1实现无扩展URL的操作。

  • Create a default ASP.NET MVC Beta project and compile it.
  • 创建一个默认的ASP.NET MVC Beta项目并进行编译。
  • Create a new IIS website pointing to the application directory.
  • 创建指向应用程序目录的新IIS网站。
  • In the IIS properties for the website, click the HomeDirectory tab.
  • 在网站的IIS属性中,单击“HomeDirectory”选项卡。
  • Click the "Configuration..." button. In the "Mappings" tab, click "Insert..."
  • 单击“配置...”按钮。在“映射”选项卡中,单击“插入...”
  • Next to the "Wildcard application maps" label In the textbox, type in "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll"
  • “通配符应用程序映射”标签旁边的文本框中,键入“c:\ windows \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll”
  • Uncheck the box labelled "Verify that file exists" Click OK
  • 取消选中标记为“验证文件是否存在”的框,然后单击“确定”
  • Navigate to /home It worked!
  • 导航到/ home它工作了!

You shouldn't need to change web.config at all. You just need to map all requests to IIS to the ASP.NET Isapi dll otherwise ASP.NET will never get those requests.

您根本不需要更改web.config。您只需要将对IIS的所有请求映射到ASP.NET Isapi DLL,否则ASP.NET将永远不会获得这些请求。

#3


1  

Unfortunatly IIS 6 needs a file extension to map the request to the right handler which means you will have to use the .mvc suffix on your controller names, such as /{controller}.mvc/{action}

不幸的是,IIS 6需要一个文件扩展名来将请求映射到正确的处理程序,这意味着您必须在控制器名称上使用.mvc后缀,例如/{controller}.mvc/{action}

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

SimplyRestfulRouteHandler.BuildRoutes(routes);

routes.MapRoute(
      "Default",
      "{controller}.mvc/{action}/{id}",
      new { controller = "Home", action = "Index", id = "" }
);

However, the are ways around this depending on your level of control on the IIS 6 server. Please refer to the following pages for more information

但是,这取决于您对IIS 6服务器的控制级别。有关更多信息,请参阅以下页面

#1


8  

OK, got it working.

好的,搞定了。

The problem was that I was using msbuild automation to package up the files that I needed to deploy, and I was missing global.asax.

问题是我使用msbuild自动化来打包我需要部署的文件,而我缺少global.asax。

So it looks like if global.asax is not deployed to the site then none of the routes get hooked up. This means that hitting the website root correctly results in the error 'The incoming request does not match any route.', and any other requests no longer get routed through to your controller classes, so result in a 404.

因此,如果没有将global.asax部署到站点,那么没有任何路由被连接起来。这意味着正确访问网站根目录会导致错误“传入的请求与任何路由都不匹配。”,并且任何其他请求不再被路由到您的控制器类,因此导致404。

HTH.

HTH。

#2


18  

Here's what I did to get extensionless URLs working with IIS 6 and ASP.NET MVC Beta 1.

以下是我使用IIS 6和ASP.NET MVC Beta 1实现无扩展URL的操作。

  • Create a default ASP.NET MVC Beta project and compile it.
  • 创建一个默认的ASP.NET MVC Beta项目并进行编译。
  • Create a new IIS website pointing to the application directory.
  • 创建指向应用程序目录的新IIS网站。
  • In the IIS properties for the website, click the HomeDirectory tab.
  • 在网站的IIS属性中,单击“HomeDirectory”选项卡。
  • Click the "Configuration..." button. In the "Mappings" tab, click "Insert..."
  • 单击“配置...”按钮。在“映射”选项卡中,单击“插入...”
  • Next to the "Wildcard application maps" label In the textbox, type in "c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll"
  • “通配符应用程序映射”标签旁边的文本框中,键入“c:\ windows \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll”
  • Uncheck the box labelled "Verify that file exists" Click OK
  • 取消选中标记为“验证文件是否存在”的框,然后单击“确定”
  • Navigate to /home It worked!
  • 导航到/ home它工作了!

You shouldn't need to change web.config at all. You just need to map all requests to IIS to the ASP.NET Isapi dll otherwise ASP.NET will never get those requests.

您根本不需要更改web.config。您只需要将对IIS的所有请求映射到ASP.NET Isapi DLL,否则ASP.NET将永远不会获得这些请求。

#3


1  

Unfortunatly IIS 6 needs a file extension to map the request to the right handler which means you will have to use the .mvc suffix on your controller names, such as /{controller}.mvc/{action}

不幸的是,IIS 6需要一个文件扩展名来将请求映射到正确的处理程序,这意味着您必须在控制器名称上使用.mvc后缀,例如/{controller}.mvc/{action}

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

SimplyRestfulRouteHandler.BuildRoutes(routes);

routes.MapRoute(
      "Default",
      "{controller}.mvc/{action}/{id}",
      new { controller = "Home", action = "Index", id = "" }
);

However, the are ways around this depending on your level of control on the IIS 6 server. Please refer to the following pages for more information

但是,这取决于您对IIS 6服务器的控制级别。有关更多信息,请参阅以下页面