CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

Custom Role Provider. Username not being detected

I have implemented a customer role provider in a C# MVC app.

It doesn't seem to be detecting the Windows user.

This was working fine yesterday.

The config for it looks like this:

  <system.web>
    <authentication mode="Windows" />
    <roleManager defaultProvider="MyRoleProvider" enabled="true">
      <providers>
        <clear />
        <add name="MyRoleProvider" type="CWC_Service_Plan.Security.MyRoleProvider" />
      </providers>
    </roleManager>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>

However adding a break-point in the code I can see that the User is not being detected.

enter image description here

I must have changed something without realising. What could be causing this?

[Edit]

Role-providers work by picking up the Windows username and then using it to authenticate.

No authentication happens if it can't pick-up the username.

The question is about why the username is not being picked-up, which I appreciate is a big question, so all suggestions are good suggestions.

[/Edit]

Upvotes: 0

Views: 164

Answers (1)

Albireo
Albireo

Reputation: 11095

Have you disabled Anonymous access?

See Configuring Windows Authentication:

  1. Start Internet Information Services (IIS).
  2. Right-click your application's virtual directory, and then click Properties.
  3. Click the Directory Security tab.
  4. Under Anonymous access and authentication control, click Edit.
  5. Make sure the Anonymous access check box is not selected and that Integrated 1. Windows authentication is the only selected check box.

This applies to Visual Studio too, it's a property of the web project (select the web project and press F4):

enter image description here

Upvotes: 1

Related Questions