0

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]

Community
  • 1
  • 1
CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
  • 1
    There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. – Albireo Nov 27 '15 at 13:00
  • I have given the config and an example of exactly what is wrong - what details would you like me to add? – CompanyDroneFromSector7G Nov 27 '15 at 13:01
  • 2
    You posted a screenshot of a debugging session. Since you're not authenticating users (User.IsAuthenticated == false) your problem lies in how you're authenticating the user, without seeing that code no-one is able to help you. – Albireo Nov 27 '15 at 13:10
  • What part of "not picking up the username" did you miss? It looks like you don't know what a custom role provider is. If you don't understand the question, skip it, don't down-vote and request to close! – CompanyDroneFromSector7G Nov 27 '15 at 13:25
  • I didn't notice you were using ``. BTW, attacking people trying to help you for free won't get you far. – Albireo Nov 27 '15 at 13:39
  • You didn't try to help, and I didn't attack you, I just pointed out your mistake. BTW, down-voting people and voting to close a question when the mistake is your own, then not apologising when you realise your error also won't get you far. – CompanyDroneFromSector7G Nov 27 '15 at 13:46

1 Answers1

1

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

Albireo
  • 10,977
  • 13
  • 62
  • 96