How to set Request.IsAuthenticated to true when not using FormsAuthentication.RedirectFromLoginPage?

前端 未结 4 424
闹比i
闹比i 2021-01-30 22:40

I am using Form Authentication and sending an Aajx request to the server for authentication. Based on the json result, the client decides where to go and what to do. That is the

4条回答
  •  迷失自我
    2021-01-30 23:06

    FormsAuthentication.SetAuthCookie

    Method Creates an authentication ticket for the supplied user name and adds it to the cookies collection of the response, or to the URL if you are using cookieless authentication.

    Ref: msdn

    Have a look at the Forms Authentication Control Flow. The authentication cookie is set to the response cookie collection, and should be observable at the http protocol level (e.g. use FireCookie or Fiddler2 to verify this).

    Membership only verifies a username/password. Neither Membership nor SetAuthCookie() will modify the current request. They expect to send the cookie back to the caller, and the next request is when the properties like IsAuthenticated will return true.

    Note that you can override and extend these automatic processes using custom IIdentity and IPrincipal, and hook into the authentication events if you need to.

    Also have a look at Using Forms Authentication with ASP.NET AJAX

提交回复
热议问题