Page redirection based on user role in ASP.Net

Last Reply on Jun 22, 2016 08:18 AM By dharmendr

Posted on Jun 21, 2016 07:43 AM

Hello,

how to navigate to 2 different paths according to current path

as example I have default.aspx in 2 directories 
1-app/default.aspx
2-app/admin/default.aspx

how to make linkbutton navigate to app/admin/default.aspx if admin press on it
and to app/default.aspx if normal user press on  it

 

Regards,
Mehad Araby

 

 

 

You are viewing reply posted by: dharmendr on Jun 22, 2016 08:18 AM.
Posted on Jun 22, 2016 08:18 AM Modified on on Jun 22, 2016 08:47 AM

Hi mehad,

Refer the below html. LinkButton doesnot have property NavigateUrl, it has PostBackUrl.

<div>
    <asp:LinkButton ID="lbNavigate" Text="Details" runat="server" OnClick="lbNavigate_Click" />
</div>

Code

protected void lbNavigate_Click(object sender, EventArgs e)
{
    string userType = "admin"; //Get usertype as per your logic.
    if (userType.ToLower() == "admin")
    {
        lbNavigate.PostBackUrl = "~/app/admin/Default.aspx";
    }
    else
    {
        lbNavigate.PostBackUrl = "~/app/Default.aspx";
    }
}