使用 ASP.NET MVC2,IIS 6 不转发空路由
首先让我解释一下,我使用的是托管解决方案,在 IIS 6 的配置和设置方面我无能为力。
我在一定程度上使用了 MVC2,我正在使用以下 Global.asax 代码
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Default", action = "Index", id = "" }
);
}
:第一条路线,我必须指定 {controller}.aspx,因为 IIS 6 无法执行非 aspx 代码(或类似的代码,不太确定)。
没关系,以下内容有效: hxxp://mysite.com/home.aspx、hxxp://mysite.com/projects.aspx、hxxp://mysite.com/contact.aspx
都是控制器,我也可以运行它们受尊重的操作。
问题是我无法正确执行空 URL(即 hxxp://mysite.com/),它给我一个“目录列表被拒绝”错误。
我的问题是,对于位于根目录的 default.aspx 文件(确实执行),我可以在不使用简单的 Response.Redirect 的情况下加载 Home 控制器吗?
谢谢你, 马修
First let me explain that I am on a hosted solution, and there is not much I can do in ways of configuration and settings for IIS 6.
I have MVC2 working to a degree, I'm using the following Global.asax code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Default", action = "Index", id = "" }
);
}
In the first route, I had to specify {controller}.aspx, due to IIS 6 not being able to execute non aspx code (or something like that, not really sure).
Which is fine, the following works:
hxxp://mysite.com/home.aspx, hxxp://mysite.com/projects.aspx, hxxp://mysite.com/contact.aspx
which are all controllers and I can run their respected actions as well.
The problem is that I can not do an empty URL properly (ie hxxp://mysite.com/), it gives me a "Directory Listing Denied" error.
The question I have, is with a default.aspx file located at root (which does execute), can I load the Home controller WITHOUT using a simple Response.Redirect?
Thank you,
Matthew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,您收到“目录列表被拒绝”意味着 isapi filetr 与 MVC 不匹配。
The fact that you are getting "Directory Listing Denied" means that the isapi filetr don't match for working with MVC.
事实上,您收到“目录列表被拒绝”意味着您没有默认文档,因此服务器正在尝试显示根文件夹上的文件列表。
将默认文档更新为“Default.aspx”之类的内容。您的托管提供商应该有一个选项。这很常见。
The fact that you are getting "Directory Listing Denied" means that you don't have a default document and therefore the server is trying to show a list of files on the root folder.
Update the Default Document to something like "Default.aspx". Your hosting provider should have an option for this. This is very common.
您可以在 IIS6 和 IIS7 上禁用此行为
You can disable this behaviour on IIS6 and IIS7