Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>FormsAuthentication and MembershipProviders are two completely different things, still they are made to work with each other very well. If you have written a persistent cookie ["Remember Me"] then next time, you can simply call <code>Membership.GetUser()</code> which will return you the <code>MembershipUser</code> instance of the currently logged in user or <code>null</code> if no user is logged in.</p> <p>So first time when user arrives and authenticates with "Remember Me", you shall write a persistent cookie as following.</p> <pre><code>FormsAuthentication.RedirectFromLoginPage(strUserName, true); </code></pre> <p>Assuming user does not logout and leaves webpage and comes back after sometime. You can simply call MembershipUser.GetUser() as following and check if the user is already logged from the persistent cookie written by FormsAuthentication.</p> <pre><code>MembershipUser someUser = Membership.GetUser(); if(someUser == null) { FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); } else { //Take where logged in users go. } </code></pre> <p>You can do this check on your Login page itself or main landing page to intercept the User account to check if he needs to change the password or if the account is disabled as in your case.</p> <h2>EDIT</h2> <p>There are two ways to do this.</p> <p>1.) Check for authentication as mentioned above in Session_Start event in global.asax and set a session key that becomes available on all pages for that particular session.</p> <p>2.) Another way is too keep a common application wide common PageBase class that inherits from System.Web.UI.Page and acts as base page class for all your asp.net pages. On the Page Load of the common PageBase class check for the authentication as mentioned above. You will have to carefully write conditional redirection in this case since this might head towards infinite redirection with no end since it will run on Page_Load of all page from the common PageBase class.</p> <pre><code>public class PageBase : System.Web.UI.Page { /// &lt;summary&gt; /// Initializes a new instance of the Page class. /// &lt;/summary&gt; public Page() { this.Load += new EventHandler(this.Page_Load); } private void Page_Load(object sender, EventArgs e) { try { AuthenticateUser(); } catch { //handle the situation gracefully. } } private AuthenticateUser() { MembershipUser someUser = Membership.GetUser(); if(someUser == null) { FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); } else { //Take where logged in users go. } } } //in your asp.net page code-behind public partial class contact : PageBase { protected void Page_Load(object sender, EventArgs e) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload