Skip to main content

ASP.NET default Login page and controller modification for using with Web Service or local method

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

<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

Popular posts from this blog

VBScript for URL link creation

We had a need to create URL link of our project on users's desktop using a script. First stage the users had enough rights on their PC's so we included the required icon file also with the script and passed the following VBScript to users to click on it to create the desktop icon link. ' Definie shell object Set objWSHShell = WScript.CreateObject("Wscript.Shell") strDesktop = objWSHShell.SpecialFolders("Desktop") ' Copy the icon file to windows Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFileCopy = objFSO.GetFile( objWSHShell.CurrentDirectory&"\icon.ico") objFileCopy.Copy ("C:\WINDOWS\system32\") ' Define link properties and create link strShortcutName = "Log In" ' Shortcut Name - Edit for the wanted name strShortcutPath = "http://thesystem.com/Login.aspx" ' Link URL - Edit to the wanted URL strIconPath = "C:\WINDOWS\syst

VBScript for compressing files in a folder and send on FTP

This is a simple vbscript compression script. works flawlessly on text files even bigger than 15GB. We have a SSIS data generation package installed on our DB server which generates huge data files for data mining operations for current year, current month. The below scripts are doing the rest; compress the files and FTP to the data mining server location.   '====================================================== ' Function : Zip datamart CSV, CTL files to local server for archive purposes. '====================================================== Function WindowsZip(sFile, sZipFile, szPath, szDate)   Set oZipShell = CreateObject("WScript.Shell")    Set oZipFSO = CreateObject("Scripting.FileSystemObject")   Set LogFile = oZipFSO.CreateTextFile(szPath & "\Logs\log_" & szDate & ".log", true)   LogFile.WriteLine("=======================================")   LogFile.WriteLine(Now & " - Com

Round the float

There are 3 types of rounding a float to integer is applicable in any language. we programmers will come across such situation in every project. the three types are, round to next bigger integer, with not considering the decimal value. round to the next smaller integer, with not considering the decimal value. round the float according to the value of decimal value, the real round of float number. The rounding methods depend on which scenario we need the round function. Follows the examples of php rounding methods. for the case 1, rounding to the next big integer, we use  ceil() function Example :  $rounded_value = ceil($floor_value); if rounded the following values, the results are like shown 2 = ceil(1.3) 2 = ceil(1.5) 2 = ceil(1.7) for the case 2, round to the next small integer, we could use floor() Example: $rounded_value = floor($floor_value); if rounded the following values, the results are like shown 1 = floor(1.3) 1 = floor(1.5) 1 = floor(1.7) for the case 3, round as