• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

IIS6 上的 ASP.NET MVC

用户头像
it1352
帮助5

问题说明

我在哪里可以找到有关在 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.

在开发面向 IIS6 的 ASP.NET MVC 应用程序时,还有什么需要考虑的吗?有什么功能不能用吗?

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.那么如何让这个透明呢?同样,没有 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.

正确答案

#1

我花了一点时间,但我想出了如何使扩展与 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://[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://[website]/ 都会重新开始工作,我认为是因为它们成功映射回 Home 控制器.所以完整的解决方案是:

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 下正常运行.(至少在我的 PC 上是这样.)

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcakfce
系列文章
更多 icon
同类精品
更多 icon
继续加载