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

  • Home
  • SEARCH
  • 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 349333
In Process

The Archive Base Latest Questions

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

Please refer to this post. I have become able to configure my web.config file

  • 0

Please refer to this post.

I have become able to configure my web.config file so that when an unauthenticated user requests a page, he is redirected to the Login.aspx page.

I have been able to do that by configuring web.config file and the following few lines of code:

protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username = this.usernameTextBox.Text;
            string password = this.passwordTextBox.Text;

            bool success = Membership.ValidateUser(username.Trim(), password.Trim());

            if (success)
            {
                FormsAuthentication.SetAuthCookie(username, true);

                Ice_Web_Portal.BO.User user = Ice_Web_Portal.BO.User.GetUserByUserName(username);

                Ice_Web_Portal.BO.UserTypeEnum loginUserType = user.UserTypeEnum;

                if (loginUserType == UserTypeEnum.Student)
                {
                    Response.Redirect("~/Student/StudentControlPanel.aspx?username=" + username);
                }
                else if (loginUserType == UserTypeEnum.Teacher)
                {
                    Response.Redirect("~/Teacher/TeacherControlPanel.aspx?username=" + username);
                }
                else if(loginUserType == UserTypeEnum.Webmaster)
                {
                    Response.Redirect(@"~/Webmaster/WebmasterControlPanel.aspx");
                }
                else
                {
                    labLoginMessage.Text = "Sorry! Type of user couldn't be determined!";
                }
            }
            else
            {
                labLoginMessage.Text = Ice_Web_Portal.BO.User.LoginMessage;
            }
        }

But the problem I am having with this is that, once a user is Authenticated, he can access all pages in the entire web application.

But I need to restrict their area of page access according to their roles. I.e. when a user with a different role requests a page, he should be automatically redirected to the Login.aspx page.

There may be a technique in which I can check for specific user-roles in the Page_Load()-event and then redirect the user to the Login.aspx page if he is not in that role. But I don’t want to do it in that way. I want to happen that automatically. I need to use only Role Provider framework and web.config file (as that was in the case of membership. I.e. I don’t need to check membership in the Page_Load event. Web.config file is automatically blocking the access).

Can anyone tell me how can I incorporate Role feature in this so that specific users are confined within their specific Role-area?

What is the Code for generating the Authorization Ticket?

  • 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:26:55+00:00Added an answer on May 12, 2026 at 11:26 am

    add sections to web.config

      <location path="page-only-allowed-to-be-accessed-by-admin.aspx">
          <system.web>
             <authorization>
               <allow roles="admin"/>
               <deny users="*" />
             </authorization>
          </system.web>
       </location>
    

    You may find this article interesting – the web.config demystified

    EDIT:

    The code for generating the Authorization ticket is in your code.

    FormsAuthentication.SetAuthCookie(username, true);
    

    which is implemented like so (using Red Gate’s Reflector)

    public static void SetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath)
    {
        Initialize();
        HttpContext current = HttpContext.Current;
        if (!current.Request.IsSecureConnection && RequireSSL)
        {
            throw new HttpException(SR.GetString("Connection_not_secure_creating_secure_cookie"));
        }
        bool flag = CookielessHelperClass.UseCookieless(current, false, CookieMode);
        HttpCookie cookie = GetAuthCookie(userName, createPersistentCookie, flag ? "/" : strCookiePath, !flag);
        if (!flag)
        {
            HttpContext.Current.Response.Cookies.Add(cookie);
            current.CookielessHelper.SetCookieValue('F', null);
        }
        else
        {
            current.CookielessHelper.SetCookieValue('F', cookie.Value);
        }
    }
    

    The RoleProvider will get the roles for a given user, so when the web.config is inspected for allowed or denied roles/users for a given section of your application, the RoleProvider will get the roles for the user and then check against the allowed/denied roles and authorize if appropriate.

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

Sidebar

Related Questions

(Please refer to SQLFiddle for a working example of this post) I have a
Please refer my this post- how to change TTNavigator (for a web url) bottom
Please refer to this fiddle . While scrolling down, the table cells appear in
Please refer to this background question. After constructing this COUNT, how would I then
Please refer my previous post here . I did changes accordingly but getting error.
You may refer to this post of mine SQL going nuts! does not accept
I refer to this page: Post array of multiple checkbox values <input type=checkbox class=box
Please refer the attached screenshot. I have an array of the checkbox and a
Please refer to the below jsfiddle code snippet: http://jsfiddle.net/JLXs5/3/ When the user clicks here,
Please refer to this picture below: I want to customize a UITableView. I achieved

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.