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

MySQL Dump cronjob on linux server

Creating mysql dump for production databases is very important. In case of any failure or malefic attack on DB, The only way to restore to previous state is by having proper mysql dump file. Follows an example mysql dump shell script with auto naming with dumping time stamp. Its important to create the shell scripts in unix mode, if you create on a PC, It'll add some unwanted character encoding, and it'll lead to some erroneous response on the script. #!/bin/bash today=`date +%Y%m%d%H%M` backup="cmtdbbackup-$today.sql" mysqldump -u user -ppassword mydb > /apps/mysql_dump/$backup Its important to create the shell script carefully. No spaces, unless its required. in between -u and user name, there is a space, but no space between -p and password. As per the usage of system, we can decide on which interval the cronjob could be set. normally the format of a crontab entry is like the following. * * * * * /apps/scripts/scheduled_job.sh >> /dev/null 2>&am

Display the list of installed packages on perl

Lets say that you are using the external vendor's hosted environment or somehow you don't know the inner things on your perl installations. how do you check the installed packages on the server using perl script? I came through the same scenario when i intended to use CGI::Cookie Package. I was unable to check the package availability. then found the following script on web after some search and filter. when applied on my site, I got the full list of installed packages use ExtUtils::Installed; my $instmod = ExtUtils::Installed->new(); foreach my $module ($instmod->modules()) { my $version = $instmod->version($module) || "Version Not Found"; print "$module — $version "; } This piece of code returns the list of packages and their versions on the system.