Request.IsAuthenticated is always false

前端 未结 10 2129
迷失自我
迷失自我 2020-12-15 04:34

Can you tell me why FormsAuthentication.SetAuthCookie(user.Name, false); is not causing Request.IsAuthenticated to be true?

Here is my code

相关标签:
10条回答
  • 2020-12-15 05:09

    Add the following code in your Web.config

    <authentication mode="Forms">
      <forms loginUrl="~/_Login/Login" timeout="30" />
    </authentication>
    

    and

      <modules>
      <remove name="FormsAuthentication" />
      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
    </modules>
    
    0 讨论(0)
  • 2020-12-15 05:10

    you must set FormsAuthentication.SetAuthCookie(acct.UserName, true); after validating user and please check you must set authentication mode="Forms" in web.config.

    0 讨论(0)
  • 2020-12-15 05:11

    I was looking for about 2 hours now to solve the problem. And in case you already got setups like you are told to in several guides (as MSDN and so) and you still got the problem, the one and only thing that will solve it is to add:

    <system.webServer>
      <modules>
         <remove name="FormsAuthentication" />
         <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
      </modules>
    <system.webServer>
    

    within the webconfig.

    0 讨论(0)
  • 2020-12-15 05:16

    Just do it

         <system.web>
        <authentication mode="Forms">
          <forms cookieless="UseCookies" loginUrl="~/User/Login" slidingExpiration="true"> 
       </forms>
        </authentication>
    ..........
    .......
      </system.web>
    
    0 讨论(0)
  • 2020-12-15 05:17

    You are checking if the user is authenticated. So use:

    if (User.Identity.IsAuthenticated) 
    

    This will fix the issue and as mentioned set the authentication element in your web.config to Forms and not Windows.

    0 讨论(0)
  • 2020-12-15 05:19

    I solve it by deleting the caches and cookies in browser.

    0 讨论(0)
提交回复
热议问题