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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:25:16+00:00 2026-05-26T09:25:16+00:00

I had define a username in and I added it to a role. Now,

  • 0

I had define a username in and I added it to a role.

Now, I use this code to check if user valid:

if (Membership.ValidateUser(txtUsername.Text, txtPassword.Text)) {
    FormsAuthentication.SetAuthCookie(txtUsername.Text, false);
    if (Roles.GetRolesForUser(txtUsername.Text).Any(role => role == "Admin")) {
        Page.Response.Redirect(ResolveUrl("~/Admin/Products.aspx"));
    }
    txtUsername.Text = "";
}

After that, I want to check in Products.aspx page if user is in a role or not. I wrote this code but it returns my local Windows username :

Context.User.Identity.Name

I thinks it should returns logged on user.

After that I will check with this code :

  if (!Context.User.IsInRole("Admin"))
        {
            Response.Redirect(ResolveUrl("~/Default.aspx"));

        }

What’s wrong with my code? How can I check for that if logged on user is in specific 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-26T09:25:17+00:00Added an answer on May 26, 2026 at 9:25 am

    Do you set the authentication-mode to Forms?

    Web.config:

    <authentication mode="Forms">
    </authentication>
    

    Also you should use Page.User.Identity.Name instead of Context.User.Identity.Name.

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

Sidebar

Related Questions

I was looking at some code and they had this line: #define WINVER 0x0501
Due to a recent issue i had some days ago (you can check this
I had created all my stored procedures with username@XX.XX.XX.XX as DEFINER value. Now, since
I'm trying to define a new type and have not had much luck finding
If you had two snippets: (global-set-key \C-d delete-char) and (define-key global-map \C-d delete-char) Is
I want to define a constant in objective-c. Previously I had the following function:
If I had two tables, users and blocked_users , how would I define the
I've had a look at the Entity Framework 4. While generating code for the
Today I had to define the WIN32_MEAN_AND_LEAN preprocessor macro in a native C++ project
Through tutorials I had learned that you can define two variables in the same

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.