Asp.net Login Control Change Error Message
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/Customize the login error message Customize the login error message [Answered]RSS 10 replies Last post Feb 16, 2012 10:44 AM by zhshqzyc ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply zhshqzyc Member 181 Points 588 Posts Customize the login error message Feb 09, 2012 08:53 AM|zhshqzyc|LINK Hello when I login and get an error "Your login attempt was not successful. Please try again." How can I customize the error? Suppose I use asp.net membership provider. Thanks. Reply avinash_bhud... Participant 1885 Points 510 Posts Re: Customize the login error message Feb 09, 2012 09:06 AM|avinash_bhudke|LINK You can give custom message on myLogin_LoginError event. protected void myLogin_LoginError(object sender, EventArgs e) here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: http://forums.asp.net/t/1767766.aspx?Customize+the+login+error+message Sign up Problem displaying custom error message using a Login Control. up vote 1 down vote favorite I have a Asp:Login control in my project, works well in terms of the setting the passing values and managing the event handlers. However the problem is despite setting the errorMessages it's always showing a * instead of the custom message. This the markup of http://stackoverflow.com/questions/7420087/problem-displaying-custom-error-message-using-a-login-control the asp:login control : In this tutorial we will demonstrate how to customize ASP.NET’s Login Control to display detailed errors for our users. Adding the Login Control At this point in http://www.aspnettutorials.com/tutorials/controls/howto-errors-login-asp4-csharp/ the tutorial I have created a new ASP.NET Empty Web Site in Microsoft Visual Web Developer and have added in a blank Web Form named Default.aspx. To add the login control, open up the Default.aspx page in Design mode and: Expand the Login tab in your toolbox. Drag and drop a Login Control onto the Web Form. Adding Error Messages At this point, we want to add asp.net login some specific error messages to this control in the event that a login attempt fails. To do this: Right click the Login Control and select Properties. In the Properties window click the Events icon. Double click the LoginError event to begin editing that method. We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 asp.net login control hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced. This method will run every time our Login Control fails to log in successfully. Here we need to determine what is causing the error. First, at the top of the class add in the following using statement: C# using System.Web.Security; 012 using System.Web.Security; This will allow us to use the Membership class which we will need to get data from our user that is attempting to login. Next, we need to add in the code to display the error messages. Add the following code to the LoginError event method: C# MembershipUser currentUser = Membership.GetUser(Login1.UserName); if (currentUser == null) { //The GetUser method could not find a user with the given name. //This indicates that the username entered does not exist. Login1.FailureText = "Invalid Username. Please try again."; } else { //Check to see if the error occurred because they are not approved. if (!currentUser.IsApproved) Login1.FailureText = "Your account has not yet been approved by an administrator."; //Check to see if they are currently locked out. else if (currentUser.IsLockedOut) Login1
{
// Determine why the user could not login...
myLogin.FailureText = "Your login attempt was not successful. Please try again.";
// Does there exist a User account for this user?
MembershipUser usrInfo = Membership.