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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:03:41+00:00 2026-05-15T11:03:41+00:00

I’ve looked around and I can’t find the concise steps that I need to

  • 0

I’ve looked around and I can’t find the concise steps that I need to take in order to implement forms authentication in my web site. I’m using C# 3.5 with an SQL Server backend.

I have a User table and UserRole table in my database.

I have 5 Directories in my app that contain aspx pages.

Admin
Common
UserRole1
UserRole2
Public

I want role based security on Admin, UserRole1 and UserRole2.

My web.config looks like so…

  <system.web>
    <authentication mode="Forms">
      <forms name=".Authentication" loginUrl="UI/Common/Login.aspx" protection="All" path="/" timeout="30" />
    </authentication>
  ...
  </sytem.web>

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

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

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

I put a Login Control in my Login.aspx page and my Login.aspx.cs currently looks like so.

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
    if ((from u in db.Users where u.UserName == Login1.UserName select u).Count() == 1)
    {
        User user = (from u in db.Users where u.UserName == Login1.UserName select u).First();
        //custom Encryption class, returns true if password is correct
        if (Encryption.VerifyHash(Login1.Password, user.Salt, user.Hash))
        {
            string myRole = (from ur in user.UserRoles where ur.UserRoleID == user.UserRoleID select ur.Role).First();
            //???    
        }
        else
        {
            e.Authenticated = false;
        }
    }
    else
    {
        e.Authenticated = false;
    }
}

Annnnd I’m stuck, I don’t know how to tell my application what my user’s role is.

Please help me 🙂

Thanks!

Edit:

I changed my Authenticate event code to

        string role = (from ur in user.UserRoles where ur.UserRoleID == user.UserRoleID select ur.Role).First();
        if (!Roles.RoleExists(role))
            Roles.CreateRole(role);
        if (Roles.FindUsersInRole(role, user.UserName).Length == 0)
            Roles.AddUserToRole(user.UserName, role);
        e.Authenticated = true;
        string returnUrl = Request.QueryString["ReturnUrl"];
        if (returnUrl == null) returnUrl = "/";
        Response.Redirect(returnUrl);

However I keep getting kicked back to the login screen.

After login is pressed Fiddler capture looks like
302 /Web/UI/Common/Login.aspx?ReturnUrl=%2fWeb%2fUI%2fAdmin%2fDefault.aspx
302 /Web/UI/Admin/Default.aspx
200 /Web/UI/Common/Login.aspx?ReturnUrl=%2fWeb%2fUI%2fAdmin%2fDefault.aspx

Edit 2:

I think I got the authentication up and running but I randomly get connection socket pipe errors.

My authentication looks like this:

        FormsAuthentication.Initialize();
    if (!Roles.RoleExists(role))
        Roles.CreateRole(role);
    if (Roles.FindUsersInRole(role, user.UserName).Length == 0)
        Roles.AddUserToRole(user.UserName, role);
    e.Authenticated = true;
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
         user.UserName,
         DateTime.Now,
         DateTime.Now.AddMinutes(30), // value of time out property
         true, // Value of IsPersistent property
         string.Empty,
         FormsAuthentication.FormsCookiePath);
    string encryptedTicket = FormsAuthentication.Encrypt(ticket);
    HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
    if (ticket.IsPersistent) authCookie.Expires = ticket.Expiration;
    authCookie.Secure = false; //set to true when https is enabled
    Response.Cookies.Add(authCookie);

    FormsAuthentication.RedirectFromLoginPage(user.UserName, true);
  • 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-15T11:03:42+00:00Added an answer on May 15, 2026 at 11:03 am

    You can use the Roles class methods, like so:

    Roles.AddUserToRole(string userName, string roleName);
    Roles.AddUserToRoles(string userName, string[] roleNames);
    Roles.AddUsersToRole(string[] userNames, string roleName);
    Roles.AddUsersToRoles(string[] userNames, string[] roleNames;
    

    Make sure you are using System.Web.Security.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.