I was trying to create a custom authentication screen without
using any of the standard ASP.Net security controls (i.e. Login control).
So, I created my custom form and was calling the
System.Web.Security.FormsAuthentication.Authenticate(UserName, Password) method.
However, it was always returning false and in fact did not appear
to even be hitting my SQL database (which contained the security)
as the failed login attempts, etc. were all unaltered. Furthermore,
I changed my connection string to be a bogus reference and the Authenticate
still simple returned false (I was expecting it to error).
I then found out that the
System.Web.Security.FormsAuthentication.Authenticate(UserName, Password) method is
for user information stored in the web.config file. Instead,
I used the System.Web.Security.Membership.ValidateUser(UserName, Password) method
which is for the user information stored in the SQL database.
NOTE: When doing this I also then set the authorization cookie by calling:
System.Web.Security.FormsAuthentication.SetAuthCookie(UserName, true);
Here is some sample code:
{
if (System.Web.Security.Membership.ValidateUser(UserName, Password))
{
System.Web.Security.FormsAuthentication.SetAuthCookie(UserName, true);
return "1|" + DateTime.Now.ToString();
}
else
return "0|Login failed!";
}
Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
ReplyDeletemicrosoft azure training in bangalore
rpa training in bangalore
best rpa training in bangalore
rpa online training
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
ReplyDeleteBest Devops online Training
Online DevOps Certification Course - Gangboard
Selenium Training in Chennai
ReplyDeleteSelenium Training
Selenium Training in Velachery
Selenium Training in OMR
Selenium Training Institute in Chennai
Selenium Training Centers in Chennai
Selenium Courses in Chennai
Selenium Course
Selenium Course Fees
Selenium Course Fees in Chennai
Selenium Course Online
Simple code and expecting output also came.Thank you. Java training in Chennai | Certification | Online Course Training | Java training in Bangalore | Certification | Online Course Training | Java training in Hyderabad | Certification | Online Course Training | Java training in Coimbatore | Certification | Online Course Training | Java training in Online | Certification | Online Course Training
ReplyDelete