MVC 应用程序中的主页未使用 IIS 7.5 正确路由

发布于 2024-12-06 01:17:14 字数 1814 浏览 3 评论 0原文

我在带有 IIS 7.5(集成模式)的 Windows Server 2008 R2 中部署了 MVC 应用程序。如果我输入地址(http://192.168.3.5:2011/),浏览器应该显示的第一个页面是登录页面。问题是,我发现它执行在控制器中找到的第一个 ActionResult 返回方法,该方法位于所谓的按字母顺序排序的列表的顶部???。另一方面,如果我输入 http://192.168.3.5:2011/Default.aspx 一切正确;它显示登录页面。我在 Global.asax 中的路由表定义为:

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

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

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

我得到的结果是它重定向到以下地址: http://192.168.3.5:2011/Account/LogOn?ReturnUrl=%2f 然后抛出配置错误:

<providers>
         <clear />
         <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" />
</providers>

有一个 LogOn 方法,它是帐户控制器中声明的第一个方法,也是按字母顺序排列的第一个控制器。

在 IIS 6.0 经典模式中工作正常,但在 IIS 7.5(集成模式)中则不然。这让我发疯。

感谢您的帮助。

问候。

I deployed an MVC app in Windows Server 2008 R2 with IIS 7.5 (Integrated Mode). The first page that the browser should show if I enter the address (http://192.168.3.5:2011/) is a Login page. The thing is that instead I found that it executes the first ActionResult returner method found in the controller that is in the top of a allegued alphabetically ordered list ???. On the other hand if I type http://192.168.3.5:2011/Default.aspx everything goes correct; it shows the Login page. My routing table in the Global.asax is defined as:

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

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

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

The outcome that I get is that it redirects to the following address: http://192.168.3.5:2011/Account/LogOn?ReturnUrl=%2f and then configuration error is thrown:

<providers>
         <clear />
         <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" />
</providers>

There is a LogOn method, which is the first one declared in the Account Controller, which is the first controller alphabeticaly ordered.

In IIS 6.0 classic mode works fine but not in IIS 7.5 (Integrated mode). This is driving me crazy.

Thank you for your help.

Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-12-13 01:17:14

在我看来,身份验证是在一种情况下配置的,而不是在另一种情况下配置的。帐户/登录具有返回 URL 参数,该参数通常是由于原始请求未经身份验证时的重定向而提供的。

It would appear to me that authentication is configured in the one case and not in the other. The Account/Logon has the return URL parameter which is typically provided due to a redirect when the original request isn't authenticated.

时光与爱终年不遇 2024-12-13 01:17:14

您可以尝试将 id 定义为 UrlParameter.Optional:

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

You can try defining id as a UrlParameter.Optional:

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Login", action = "Login", id = UrlParameter.Optional } // Parameter defaults
            );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文