ASP.NET MVC在IIS6上 [英] ASP.NET MVC on IIS6

查看:172
本文介绍了ASP.NET MVC在IIS6上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到一些关于在IIS6上运行ASP.NET MVC的最佳做法的指针?

Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6?

我没有看到任何真实的选项,提供IIS7托管。主要是因为我不在美国。

I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S.

所以我想知道如何最好地在ASP.NET MVC中构建应用程序,并使其易于部署在IIS6上和IIS7。请记住,这是标准的网络主机,所以不能访问IIS6中的ISAPI筛选器或特殊设置。

So I was wondering on how you best build applications in ASP.NET MVC and make it easily available to deploy on both IIS6 and IIS7. Keep in mind that this is for standard web-hosts, so there is no access to ISAPI-filters or special settings inside IIS6.

还有什么需要考虑的当开发ASP.NET MVC应用程序来定位IIS6?任何不起作用的功能?

Are there anything else one should think about when developing ASP.NET MVC-applications to target IIS6? Any functions that doesn't work?

更新:其中一个较大的问题是路由问题。模式{controller} / {action}将适用于IIS7,但不适用于需要{controller} .mvc / {action}的IIS6。那么如何使这个透明?再次, no ISAPI 没有IIS设置

UPDATE: One of the bigger issues is the thing with routes. The pattern {controller}/{action} will work on IIS7, but not IIS6 which needs {controller}.mvc/{action}. So how do I make this transparent? Again, no ISAPI and no IIS-settings, please.

推荐答案

我花了一点时间,但我想出了如何使扩展与IIS 6一起工作。首先,您需要重新设计基本路由以包含.aspx,以便它们将通过ASP.NET ISAPI筛选器路由。 p>

It took me a bit, but I figured out how to make the extensions work with IIS 6. First, you need to rework the base routing to include .aspx so that they will be routed through the ASP.NET ISAPI filter.

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}.aspx/{action}/{id}",                      // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

如果您导航到Home.aspx,例如,您的网站应该可以正常工作。但是Default.aspx和 http:// [website] / 的默认页面地址停止正常工作。那么如何修复?

If you navigate to Home.aspx, for example, your site should be working fine. But Default.aspx and the default page address of http://[website]/ stop working correctly. So how is that fixed?

那么你需要定义第二个路由。不幸的是,使用Default.aspx作为路由不能正常工作:

Well, you need to define a second route. Unfortunately, using Default.aspx as the route does not work properly:

routes.MapRoute(
    "Default2",                                             // Route name
    "Default.aspx",                                         // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

那么你如何让这个工作?那么这是你需要原始路由代码的地方:

So how do you get this to work? Well, this is where you need the original routing code:

routes.MapRoute(
    "Default2",                                             // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

当您执行此操作时,Default.aspx和 http:// [网站] / 都开始工作,我认为是因为它们成功地映射回了家庭控制器。所以完整的解决方案是:

When you do this, Default.aspx and http://[website]/ both start working again, I think because they become successfully mapped back to the Home controller. So the complete solution is:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}.aspx/{action}/{id}",                      // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

        routes.MapRoute(
            "Default2",                                              // Route name
            "{controller}/{action}/{id}",                            // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );
    }

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

您的网站应该在IIS 6下开始工作(至少在我的电脑上)。

And your site should start working just fine under IIS 6. (At least it does on my PC.)

作为一个奖励,如果你在你的网页上使用Html.ActionLink(),你不应该改变整个网站的任何其他代码行。此方法可以在控制器的.aspx扩展名上正确标记。

And as a bonus, if you are using Html.ActionLink() in your pages, you should not have to change any other line of code throughout the entire site. This method takes care of properly tagging on the .aspx extension to the controller.

这篇关于ASP.NET MVC在IIS6上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆