locked
Give Access To each page Based On Login RRS feed

  • Question

  • User-807418713 posted

    Hello

    if (HttpContext.Current.User.Identity.Name == "user1") 
         {    
                 Response.Redirect("A.aspx"); 
         }

    This is my code 

    i have three user user1,user2,user3

    If user1 login it should goes A.aspx

    If user2 login it should goes B.aspx

    If user3 login it should goes C.aspx

    How to check this via login.aspx page im using asp.net login

    Saturday, July 7, 2018 6:50 AM

Answers

  • User-369506445 posted

    you have to write is after <g class="gr_ gr_18 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="18" data-gr-id="18">get</g> login success status,

    for example

     var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
    
    
    if (result==true) // user login was succsess
    {
    switch (HttpContext.Current.User.Identity.Name)
                    {
                        case "user1":
                            Response.Redirect("A.aspx");
                            break;
                        case "user2":
                            Response.Redirect("B.aspx");
                            break;
                        case "user3":
                            Response.Redirect("C.aspx");
                            break;
                    }
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2018 8:02 AM
  • User409696431 posted

    If you are using the 2.0/3.5 login control, use the loggedin event to redirect your users.  This event occurs after the user is authenticated and logged in.  Use the Login1.Username and switch based on that.

    On your page:

    <asp:Login id="Login1" runat="server" OnLoggedIn="OnLoggedIn"></asp:Login>

    In your code-behind:

    protected void OnLoggedIn(object sender, EventArgs e)
    {
       switch (Login1.UserName)
                    { case "user1": Response.Redirect("A.aspx"); break; case "user2": Response.Redirect("B.aspx"); break; case "user3": Response.Redirect("C.aspx"); break; } }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2018 11:00 PM

All replies

  • User-369506445 posted

    hi

    you can check it with a <g class="gr_ gr_50 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="50" data-gr-id="50">swtich</g> statement below like 

    switch (HttpContext.Current.User.Identity.Name)
                    {
                        case "user1":
                            Response.Redirect("A.aspx");
                            break;
                        case "user2":
                            Response.Redirect("B.aspx");
                            break;
                        case "user3":
                            Response.Redirect("C.aspx");
                            break;
                    }

    Saturday, July 7, 2018 7:32 AM
  • User-807418713 posted

    Hello

    Thanks for your code

    where to write this code in asp.net login page...

    Saturday, July 7, 2018 7:54 AM
  • User-369506445 posted

    you have to write is after <g class="gr_ gr_18 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="18" data-gr-id="18">get</g> login success status,

    for example

     var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
    
    
    if (result==true) // user login was succsess
    {
    switch (HttpContext.Current.User.Identity.Name)
                    {
                        case "user1":
                            Response.Redirect("A.aspx");
                            break;
                        case "user2":
                            Response.Redirect("B.aspx");
                            break;
                        case "user3":
                            Response.Redirect("C.aspx");
                            break;
                    }
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2018 8:02 AM
  • User-807418713 posted

    Hello

    I'm using asp.net 2.0 Login control

    I dont know in which event i have to write your code

    can you please guide me

    Thanking You

    Saturday, July 7, 2018 8:08 AM
  • User-369506445 posted

    which event is your login? put the last code into that place

    Saturday, July 7, 2018 8:33 AM
  • User-1171043462 posted

    Refer ASP.Net Login Control example with Database using C#

    In the ValidateUser event modify

    protected void ValidateUser(object sender, EventArgs e)
    {
        int userId = 0;
        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("Validate_User"))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Username", Login1.UserName);
                cmd.Parameters.AddWithValue("@Password", Login1.Password);
                cmd.Connection = con;
                con.Open();
                userId = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
            }
            switch (userId)
            {
                case -1:
                    Login1.FailureText = "Username and/or password is incorrect.";
                    break;
                case -2:
                    Login1.FailureText = "Account has not been activated.";
                    break;
                default:
                    FormsAuthentication.SetAuthCookie(Login1.Username, Login1.RememberMe);
    		switch (Login1.Username)
                    {
                        case "user1":
                            Response.Redirect("~/PageA.aspx");
                            break;
                        case "user2":
                            Response.Redirect("~/PageB.aspx");
                            break;
                        case "user3":
                            Response.Redirect("~/PageC.aspx");
                            break;
                    }
                    break;
            }
        }
    }
    


    this code

    Saturday, July 7, 2018 7:15 PM
  • User409696431 posted

    If you are using the 2.0/3.5 login control, use the loggedin event to redirect your users.  This event occurs after the user is authenticated and logged in.  Use the Login1.Username and switch based on that.

    On your page:

    <asp:Login id="Login1" runat="server" OnLoggedIn="OnLoggedIn"></asp:Login>

    In your code-behind:

    protected void OnLoggedIn(object sender, EventArgs e)
    {
       switch (Login1.UserName)
                    { case "user1": Response.Redirect("A.aspx"); break; case "user2": Response.Redirect("B.aspx"); break; case "user3": Response.Redirect("C.aspx"); break; } }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2018 11:00 PM
  • User-369506445 posted

    Please refer to below link

    https://www.tutorialspoint.com/asp.net/asp.net_security.htm

    Sunday, July 8, 2018 7:01 PM
  • User-330142929 posted

    Hi Gopi.MCA,

    According to your description, you want to redirect users after verifying user authentication permissions.

    I'm using asp.net 2.0 Login control

    I dont know in which event i have to write your code

    If you are using the login control, I think the logic code should be putted in the LoggedIn event handler。

    Just like this.

           protected void Login1_LoggedIn(object sender, EventArgs e)
            {
                bool result = IdentityManager.authenticate(user);
                if (result)
                {
                    switch (HttpContext.Current.User.Identity.Name)
                    {
                        
     
                    }
     
                }
            }

    Feel free to let me know if you have any questions.

    Best Regards

    Abraham

    Monday, July 9, 2018 6:38 AM