<p>We have got a custom <code>MembershipProvider</code> in <code>ASP.NET</code>. Now there are 2 possible scenario the user can be validated:</p>

<ol>
<li><p>User login via <code>login.aspx</code> page by entering his username/password. I have used <strong>Login control</strong> and linked it with the <code>MyMembershipProvider</code>. This is working perfectly fine.</p></li>
<li><p>An authentication token is passed via some URL in query string form a different web sites. For this I have one overload in <code>MembershipProvider.Validate(string authenticationToken)</code>, which is actually validating the user. In this case we cannot use the <strong>Login control</strong>. Now how can I use the same <code>MembershipProvider</code> to validate the user without actually using the <strong>Login control</strong>? I tried to call <code>Validate</code> manually, but this is not signing the user in.</p></li>
</ol>

<p>Here is the code snippet I am using </p>

<pre><code>if (!string.IsNullOrEmpty(Request.QueryString["authenticationToken"])) {
    string ticket = Request.QueryString["authenticationToken"];
    MyMembershipProvider provider = Membership.Provider as MyMembershipProvider;
    if (provider != null) {
        if (provider.ValidateUser(ticket))
            // Login Success
        else
            // Login Fail
    }
}
</code></pre>

[{'answer_id': 41664, 'author': 'MartinHN', 'author_id': 2972, 'author_profile': 'https://Stackoverflow.com/users/2972', 'pm_score': 5, 'selected': True, 'text': '<p>After validation is successful, you need to sign in the user, by calling FormsAuthentication.Authenticate: <a href="http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx</a></p>\n\n<p>EDIT: It is FormsAuthentication.SetAuthCookie:\n<a href="http://msdn.microsoft.com/en-us/library/twk5762b.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/twk5762b.aspx</a></p>\n\n<p>Also, to redirect the user back where he wanted to go, call: FormsAuthentication.RedirectFromLoginPage: <a href="http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirectfromloginpage.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirectfromloginpage.aspx</a> </p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx" rel="nofollow noreferrer">link text</a></p>\n'}, {'answer_id': 42151, 'author': 'JasonS', 'author_id': 1865, 'author_profile': 'https://Stackoverflow.com/users/1865', 'pm_score': 2, 'selected': False, 'text': '<p>You can set your own <code>FormsAuthenticationTicket</code> if the validation is successful.</p>\n\n<p>Something like this;</p>\n\n<pre><code>if (provider != null) {\n    if (provider.ValidateUser(ticket)) {\n        // Login Success\n        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(\n            1, //version\n            someUserName, //name\n            DateTime.Now, //issue date\n            DateTime.Now.AddMinutes(lengthOfSession), //expiration\n            false, // persistence of login\n            FormsAuthentication.FormsCookiePath\n        );\n\n        //encrypt the ticket\n        string hash = FormsAuthentication.Encrypt(authTicket);\n        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);\n\n        Response.Cookies.Add(cookie);\n        Response.Redirect(url where you want the user to land);\n    } else {\n        // Login Fail  \n    }   \n}\n</code></pre>\n'}, {'answer_id': 5698869, 'author': 'Bernd', 'author_id': 712841, 'author_profile': 'https://Stackoverflow.com/users/712841', 'pm_score': 1, 'selected': False, 'text': '<p>You are right in the case of storing the auth information as a cookie directly. But using a strong hash function (e.g. MD5 + SHA1) is great and secure.\nBy the way, if you use sessions (which is also just a hash cookie) you could attach auth information to it.</p>\n'}]
['https://Stackoverflow.com/questions/41652', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/191/']