简体   繁体   English

总是将ASP.NET MVC重定向到登录页面

[英]ASP.NET MVC redirect to logon page always

I am using ASP.NET independent membership in my own way. 我以自己的方式使用ASP.NET独立成员身份。 To achieve it, I set FormsAuthentication.SetAuthCookie when user has logged in my system and i also removed all membership relation configurations like profile, role and membership settings from web.config. 为此,我在用户登录系统时设置FormsAuthentication.SetAuthCookie,并且还从web.config中删除了所有成员关系配置,例如配置文件,角色和成员资格设置。

Problem is that i can not access any controller. 问题是我无法访问任何控制器。 ASP.NET MVC redirect me to /Account/Logon page but even i can not catch breakpoint in LogOn action method and i dont see any content parsed as a result. ASP.NET MVC将我重定向到/ Account / Logon页面,但即使我在LogOn操作方法中也无法捕获断点,因此也看不到任何已解析的内容。

What can cause this strange behavior really ? 究竟是什么会导致这种奇怪的行为? Please ask if you need extra information to understand problem. 请询问您是否需要其他信息以了解问题。

My web.config settings are at below. 我的web.config设置在下面。

<configuration>
  <configSections>

  </configSections>

  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="enableSimpleMembership" value="false" />
    <add key="autoFormsAuthentication" value="false" />
  </appSettings>
  <system.web>
    <globalization uiCulture="tr-TR" culture="tr-TR" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral,  PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral,       PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral,       PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral,           PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral,      PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <httpModules></httpModules>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration> 

Because you say you aren't hitting a breakpoint in your Logon Post action, it would suggest that you have AuthoriseAttribute set on the Logon Post method (or set globally in RegisterGlobalFilters ). 因为您说您没有在“登录后”操作中达到断点,所以建议您在“登录后”方法上设置AuthoriseAttribute (或在RegisterGlobalFilters全局设置)。 The Logon Post method needs to be accessibly Anonymously, or it won't be able to receive the username and password. Logon Post方法需要匿名访问,否则将无法接收用户名和密码。

I'd suggest you post the relevant Actions from your Account controller, and the contents of your Global.asax RegisterGlobalFilters method if this doesn't help, 建议您从“帐户”控制器中发布相关的“操作”,如果没有帮助,则发布Global.asax RegisterGlobalFilters方法的内容,

Exactly like Richard mentioned, I think this article also shows you how to apply the AllowAnonymousAttribute with AuthoriseAttribute applied for your MVC project. 就像理查德提到的一样,我认为本文还向您展示了如何将AllowAnonymousAttribute与应用于MVC项目的AuthoriseAttribute一起应用。 http://weblogs.asp.net/jgalloway/archive/2012/04/18/asp-net-mvc-authentication-global-authentication-and-allow-anonymous.aspx http://weblogs.asp.net/jgalloway/archive/2012/04/18/asp-net-mvc-authentication-global-authentication-and-allow-anonymous.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM