How to tell the user exactly why the login failed in asp.net

I have a membership provider, and I have several reasons why the login may fail, and I need to transfer it to the user.

All I read is related to lots of code.

Is there an easy way to do this?

+4
source share
1 answer

Of course.

You can put out-of-band data in a context when in your provider, and then pick it up in the error handler of your input control to set the rejection text.

public override bool ValidateUser(string username, string password) { // in membership provider HttpContext.Current.Items["loginFailureReason"] = "Locked Out"; return false; } // in login codebehind protected void Login1_LoginError(object sender, EventArgs e) { Login1.FailureText = (string) HttpContext.Current.Items["loginFailureReason"]; } 
+6
source

Source: https://habr.com/ru/post/1311033/


All Articles