Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I will read my DATA from SQL for users ROLE but know i want to Navigate after check from Web.Config File Login Form can read and navigate to other pages.
But the Below code i tried but i could not get results. Please help me to write complete procee with code.Thanks
Thanks

C#
protected void LoginButton_Click(object sender, EventArgs e)
    {
        //bool  str = User.IsInRole("Administrator");
        ////str = true;
        if (User.IsInRole("Administrator"))
        {
            Response.Redirect("~/Administration/TaskAllocation.aspx");

        }
        else if (User.IsInRole(UserNameTextBox.Text))
        {
            Response.Redirect("~/Staff/Default.aspx");
        }
        else
        {
            Response.Redirect("~/Login.aspx");

        }
    }


XML
<?xml version="1.0"?>

<configuration>
  <!--<location path="~/App-Themes/CSS">-->
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Forms">
      <forms loginUrl="~/Login.aspx"  timeout="60" cookieless="UseCookies" protection="All" >
      </forms>
    </authentication>
    <authorization>
      <!--<allow users="*"/>-->
    </authorization>
    <roleManager    enabled="true" cacheRolesInCookie="true"  >
    </roleManager>


    </system.web>
  <!--</location>-->
  <!--Here is giving Access to Administrator Folder and Pages in it.-->
  <location path="Administration">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users="*"/>
      </authorization>

    </system.web>

  </location>

  <location path="Staff">
    <system.web>
      <authorization>
        <allow roles="Staff"/>
        <deny users= "*"/>
      </authorization>
    </system.web>

  </location>

</configuration>
Posted
Updated 8-Jan-15 1:30am
v2
Comments
Kornfeld Eliyahu Peter 8-Jan-15 6:33am    
And what the question is?
Muhammad Nabeel 8-Jan-15 7:33am    
I have change my Quetion. But i want to know how i can Access roles in C# Behind button code and if statments.this code is not navigating after click login.May be i have misssing some code
Arjsrya 8-Jan-15 7:40am    
where are you storing the roles of user in db?Could you share you registeration code?
Muhammad Nabeel 8-Jan-15 7:48am    
I will store in SQL DB.....But here in my C# Code i have write role in If condition and
if (User.IsInRole("Administrator"))
{
Response.Redirect("~/Administrator/TaskAllocation.aspx");

}
else
{
Response.Redirect("~/Default.aspx");

}

also in web.config i have also authentication


<location path="Administration">
<system.web>
<authorization>
<allow roles="Administrator">
<deny users="*">





Arjsrya 8-Jan-15 7:28am    
Could you please explain your question a little bit clearly?Are you storing users with different roles in the database?Where are you getting the user role while logging into the application?

Please look into google first and get the full knowledge on it.ask your questions further.

Please find below url which helps your requirement.

http://www.aspsnippets.com/Articles/Implement-Role-based-security-using-Forms-Authentication-in-ASPNet.aspx

1 solution

XML
I will store in SQL DB.....But here in my C# Code i have write role in If condition and
    if (User.IsInRole("Administrator"))
        {
            Response.Redirect("~/Administrator/TaskAllocation.aspx");

        }
        else
        {
            Response.Redirect("~/Default.aspx");

        }

 also in web.config i have also authentication


<location path="Administration">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users= "*"/>
      </authorization>


    </system.web>

  </location>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900