By default the ASP.NET login page and controls are bound with default methods and its bit uneasy to work with ( at least for some ppl like me). We could make use of same controller and pages with our own mechanism of logging in.
1. Changes on web.config
2. Moving files
Move the Login.aspx and related files outside the default folder and delete the folder
3. Update on Login frontend, add the onclick method
4. Update on Login backend
1. Changes on web.config
<location path="Login.aspx"><system.web><authorization><allow users="*" /></authorization></system.web></location><location path="Styles"><system.web><authorization><allow users="*" /></authorization></system.web></location><location path="Images"><system.web><authorization><allow users="*" /></authorization></system.web></location><system.web><authorization><deny users="?" /></authorization></system.web>
2. Moving files
Move the Login.aspx and related files outside the default folder and delete the folder
3. Update on Login frontend, add the onclick method
<p class="submitButton"><asp:Button ID="LoginButton" runat="server" onclick="LoginButton_Click" Text="Log In" ValidationGroup="LoginUserValidationGroup"/></p>
4. Update on Login backend
protected void LoginButton_Click(object sender, EventArgs e){bool authSuccess = false;sc.AppCode = WebConfigurationManager.AppSettings["appCode"];sc.AppPwd = WebConfigurationManager.AppSettings["appPwd"];sc.ClientIP = "aa";sc.EndUserId = "aa";try{if (LoginUser.UserName == WebConfigurationManager.AppSettings["userId"]) // web.config user id{if (LoginUser.Password == WebConfigurationManager.AppSettings["userPwd"]){authSuccess = true;}else{authSuccess = false;}}else // other user id{req.ServiceContext = sc;req.UserId = LoginUser.UserName;req.UserPwd = LoginUser.Password;try{response = port.Authenticate(req);if(response.Status.ToUpper() == "OK"){authSuccess = true;}else{authSuccess = false;wsStatus.Text = response.Message;}}catch (Exception lex){wsStatus.Text = lex.Message;authSuccess = false;}}//if (authSuccess){FormsAuthentication.SetAuthCookie(LoginUser.UserName, false /* createPersistentCookie */);string continueUrl = Request.QueryString["ReturnUrl"];if (String.IsNullOrEmpty(continueUrl)){continueUrl = "~/";}Response.Redirect(continueUrl);}else{LoginUser.FailureText = "Login Failure!";}}catch (Exception lex){LoginUser.FailureText = lex.Message;}}
Comments
Post a Comment