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

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

问题描述

在哪里可以找到最佳实践一些好的指针在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。请记住,这是标准的Web主机,所以里面的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?

更新:其中一个更大的问题是路线的东西。该模式{控制器} / {行动}将工作的IIS7,但不IIS6,需要{}控制器.mvc / {行动}。那么,如何使这个透明?此外,否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筛选器进行路由。

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的默认页面地址:// [公司网址] /停止正常工作。那么如何实现这固定的吗?

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
);

那么,你如何得到这个工作?好吧,这是你所需要的原始路由code:

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(),你不应该改变code任何其他线路贯穿整个网站。这种方法需要适当地标记在.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.

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

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