Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forms Authentication in Page_Load Event

I have a form called frmLogin. I have code within the Login_1Authenticate event handler that checks the security level of the username and password entered. Then depending on the security level it will display or not display links on my main form called frmMain. If it is security level “A” I want full control, but if it security level “U” then I want link buttons and image buttons removed from frmMain. An example of two of them to disable are:

linkbtnEmployee
imgbtnNewEmployee

linkbtnViewUserActivity
imgbtnViewUserActivity

I need to write the code for the Page_Load event, but I’m not sure how to write it. Here’s the code for my frmLogin page:

public partial class frmLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {

        dsUser dsUserLogin;


        string SecurityLevel;


        dsUserLogin = clsDataLayer.VerifyUser(Server.MapPath("PayrollSystem_DB.mdb"),
                         Login1.UserName, Login1.Password);


        if (dsUserLogin.tblUserLogin.Count < 1)
        {
            e.Authenticated = false;
            return;
        }


        SecurityLevel = dsUserLogin.tblUserLogin[0].SecurityLevel.ToString();


        switch (SecurityLevel)
        {

            case "A":
                // Add your comments here
                e.Authenticated = true;
                Session["SecurityLevel"] = "A";
                break;
            case "U":
                // Add your comments here
                e.Authenticated = true;
                Session["SecurityLevel"] = "U";
                break;
            default:
                e.Authenticated = false;
                break;
        }
    }
}
like image 239
Mike Avatar asked Apr 08 '26 09:04

Mike


1 Answers

Well if you want them to be invisible use:

linkbtnEmployee.Visible = false;
imgbtnNewEmployee.Visible = false;
like image 147
Tudor Avatar answered Apr 10 '26 23:04

Tudor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!