Solved

WindowsTokenRoleProvider IsInRole

Posted on 2011-09-17
9
356 Views
Last Modified: 2012-05-12
I have an intranet app where I am allowing access to certain pages based on the department the user belongs.  Works fine in debug mode, but when I deploy to my local IIS, my code does not work properly.  

I am using

            var User = System.Web.HttpContext.Current.User;
            var wi = new WindowsTokenRoleProvider();
                if (wi.IsUserInRole(User.Identity.Name, "Domain\\RSExecutive").ToString().ToLower() == "true")
                {
                    Session.Add("manager", "Yes");
                }
     else
                {
                    Session.Add("manager", "No");
                }

Open in new window


Works fine debugging.  I get a value of True as expected. Once I publish, I get False, which is incorrect.. Windows Authentication mode, impersonation set to true, and Role provider is AspNetWindowsTokenRoleProvider

This is a 2010 environment and in 4.0

Thanks in advance.
0
Comment
Question by:rmartin15
  • 4
  • 3
9 Comments
 

Author Comment

by:rmartin15
Comment Utility
Sorry, another clue I should've mentioned.

Debugging,  my domain\username is displayed per the design.  Published,   No username is displayed.  So something in the published environment prevents my windows account info from being read.

Thanks
0
 
LVL 4

Expert Comment

by:guramrit
Comment Utility
Try to check the value of User.IsAuthenticated. See if it's false.
0
 

Author Comment

by:rmartin15
Comment Utility
Thanks.

I did that and the user is not Authenticated
0
 
LVL 4

Expert Comment

by:guramrit
Comment Utility
Make sure WindowsAuthentication is not disabled. and see http://stackoverflow.com/questions/6251918/windows-authentication-problem-in-iis-7-5 for reference.

Now make that page restricted to logged in users through web.config, then upon visiting that page you'll see a login form. Enter details and check your result.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:guramrit
Comment Utility
or Try using following code in web.config
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication enabled="false"/>
        <windowsAuthentication enabled="true" />
      </authentication>
    </security>
  </system.webServer>

I've disabled anonymousAuthentication to make login form show.
0
 

Author Comment

by:rmartin15
Comment Utility
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Here is the error I receive when going to my website

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

I'll look into resolving this issue.
0
 
LVL 4

Accepted Solution

by:
guramrit earned 500 total points
Comment Utility
I've reproduced this error on my side too.
Now, you'll need to made some changes to applicationhost.config, which you can find at %systemroot%\System32\inetsrv\config\applicationHost.config.

1. look this file for
    <add name="WindowsAuthenticationModule" lockItem="true" />
               and change it to
     <add name="WindowsAuthenticationModule" lockItem="false" />

2. <section name="anonymousAuthentication" overrideModeDefault="Deny" />
            to
     <section name="anonymousAuthentication" overrideModeDefault="Allow" />

3. <section name="windowsAuthentication" overrideModeDefault="Deny" />
             to
    <section name="windowsAuthentication" overrideModeDefault="Allow" />

0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now