Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 348691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:23:18+00:00 2026-05-12T11:23:18+00:00

I am using asp.net forms authentication, membership provider and role provider. You can refer

  • 0

I am using asp.net forms authentication, membership provider and role provider.

You can refer to this post.

This post helped me to restrict access of the users to the specific areas of Web application according to their roles.

But the roles are hard-coded in the Web.config file.

I need to read the roles from the asp.net role provider database.

I want to use the database generated by this command:
[C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql]

and the following tool:

alt text

and [aspnetdb] database.

And I want to use microsoft’s framework and avoid my own customization as far as possible.

Plz tell me how can I generate authentication and authorization ticket. Better if you can show me some C# code.

Can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:23:19+00:00Added an answer on May 12, 2026 at 11:23 am

    If you have already wired Authentication and Membership using SQL Server in your site it will be easy for you. Just follow these steps:

    Create role store on sql server

       aspnet_regsql -S .\SQLExpress -E -A r
    
        -S specifies the server, which is (.\SQLExpress) in this example.
        -E specifies to use Windows authentication to connect to SQL Server.
        -A r specifies to add only the role provider feature.
    

    Add connection string for role provider:

    <connectionStrings>
      <add name="MyLocalSQLServer"
           connectionString="Initial Catalog=aspnetdb;
          data source=.\sqlexpress;Integrated Security=SSPI;" />
    </connectionStrings>
    

    Add role manager:

    <system.web>
      <roleManager enabled="true" defaultProvider="MySqlRoleProvider" >
        <providers>
          <clear/>
          <add name="MySqlRoleProvider" connectionStringName="MyLocalSQLServer"
               applicationName="MyAppName"
               type="System.Web.Security.SqlRoleProvider" />
        </providers>
      </roleManager>
    </system.web>    
    

    Now you can use Role based stuff in your pages (supposing you have already enabled authentication [windows or forms])

    Test ASPX:

        All Defined Roles: <asp:Lable id="lblAllRoles" runat="server" /><br/>
        Your Roles: <asp:label id="lblMyRoles" runat="server" /><br/>
    

    Codebehind:

        protected void Page_Load(object sender, EventArgs e)
        {
            //here we are supposing that user is already authenticated
    
            StringBuilder sb=new StringBuilder();
    
            //gets roles for currently authenticated user
            var roles = Roles.GetRolesForUser();            
    
            foreach (var v in roles)
                sb.Append(", " + v);
    
            lblMyRoles.Text = sb.ToString();
            sb.Remove(0,sb.Length);
    
            string [] allRoles = Roles.GetAllRoles();
            foreach(var v in allRoles)
               sb.Append(", " + v);
    
            lblAllRoles.Text = sb.ToString();
        }
    

    Simillarly you can use Role.IsUserInRole("ROLE_NAME") to check if user is assigned particular role.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using web forms authentication with the ASP.NET Membership provider, we are defaulted to
I'm using the ASP.NET Login Controls and Forms Authentication for membership/credentials for an ASP.NET
I'm using the ASP.NET Login Controls and Forms Authentication for membership/credentials for an ASP.NET
How exactly can one implement a Log off function when using ASP.NET Forms Authentication
I have an asp.net application which is using form authentication, asp.net membership provider (ASP.NET
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
Using Forms Authentication in ASP.NET MVC when trying to log back into a site,
I'm using forms authentication on a very small ASP.NET web app (Web Forms) in
I have an ASP.NET 3.5 app using Forms Authentication. It would be nice to
I have an ASP.NET web application that is using forms authentication. Everything is configured

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.