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 4533618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:10:42+00:00 2026-05-21T14:10:42+00:00

I inherited an ASP.NET C# application that is not totally working. I have been

  • 0

I inherited an ASP.NET C# application that is not totally working. I have been told to use Form Authentication to prevent unauthorized users from accessing certain subdirectories.

I am having a problem understanding Forms Authentication. This is a public internet site and all users will have access to the main part of the site. However there is a subdirectory that is restricted to certain users. I know that a user is valid because they will enter a user name and password and I will look them up in a database. I have added these lines to the web.config file of the subdirectory.

<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <authorization>
      <allow roles="Administrators, Examiners"/>
            <deny users="*"/>
        </authorization>
    </system.web>

The question is how do I set in my code that the user belongs to a certain role.

Here is the pseudo code.

If user name and password match then

Set this users role to Examiners.

I don’t know the code I need to set the user to a role.

  • 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-21T14:10:43+00:00Added an answer on May 21, 2026 at 2:10 pm

    Take a look at your membership database.

    • You can create your own membership database by Creating the Membership Schema in SQL Server here. There you will find a table with the name aspnet_roles. Within this table you can define different roles.
    • There is also a great tutorial for using the built in Membership Provide Tool in Visual Studio to maintain your membership database that you shuold look into as well.

    To make a start here you go with the login method:

    protected void LoginButton_Click(object sender, EventArgs e)
    {
     // Validate the user against the Membership framework user store
     if (Membership.ValidateUser(UserName.Text, Password.Text))
     {
     // Log the user into the site
     FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);
     }
     // If we reach here, the user's credentials were invalid
     InvalidCredentialsMessage.Visible = true;
    }
    

    you can check the user credentials within the authenticate method:

    protected void myLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
     // Get the email address entered
     TextBox EmailTextBox = myLogin.FindControl("Email") as TextBox;
     string email = EmailTextBox.Text.Trim();
    
     // Verify that the username/password pair is valid
     if (Membership.ValidateUser(myLogin.UserName, myLogin.Password))
     {
     // Username/password are valid, check email
     MembershipUser usrInfo = Membership.GetUser(myLogin.UserName);
     if (usrInfo != null && string.Compare(usrInfo.Email, email, true) == 0)
     {
     // Email matches, the credentials are valid
     e.Authenticated = true;
     }
     else
     {
     // Email address is invalid...
     e.Authenticated = false;
     }
     }
     else
     {
     // Username/password are not valid...
     e.Authenticated = false;
     }
    }
    

    For redirection depending on a specific role use this code:

    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        if (Roles.IsUserInRole(Login1.UserName, "Admin"))
        {
             Response.Redirect("~/Admin/Default.aspx");
        }
        else if (Roles.IsUserInRole(Login1.UserName, "Examiner"))
        {
             Response.Redirect("~/Examiner/Default.aspx");
        }
        else
        {
             Response.Redirect("~/Login.aspx");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have an asp.net Web Application (Not Web Site) that I am trying
I have inherited a webforms application that was working and now is not. The
I have inherited an application that uses the ASP.NET membership provider for user management.
I inherited an ASP.NET application that builds pages with massive viewstate values. As I
I have a ASP.NET application I've inherited from the person who did my job
I am working on a ASP.Net web forms application which I inherited from a
I have inherited a reasonable sized ASP.net solution that has no automated tests. The
I have an ASP.NET application that accesses private key in a certificate in the
I'm working on a web application that uses ASP.NET 3.5 and C#. Structurally, I
I have inherited a function in an ASP.NET (C#) application where the author used

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.