1

I have a Web API using the ADO.NET Framework and I removed the authentication and authorization fields in the web.config file, yet in google chrome the authentication window keeps coming.

How to remove the window ?enter image description here

I tried removing the authorization element, authentication element and yet the authentication window keeps popping. I tried making it set to NONE and still the window keeps coming.

I am running the api on localhost and when I cut the window, I obviously get the error message:

    {
  "error":{
    "code":"","message":"Authorization has been denied for this request."
  }
}

My contoller has no authentication or authorization headers and I have just one function in my contoller class which is derived from OData Controller class.

  [HttpGet, EnableQuery]
  public IQueryable<Record> GetRecord(ODataQueryOptions<Record> options)
Jim Aho
  • 9,932
  • 15
  • 56
  • 87
Novak007
  • 426
  • 1
  • 9
  • 23
  • 3
    What auth methods are enabled in your IIS? – UserControl Jun 02 '15 at 11:33
  • 3
    Post the controller's code - does it have any authentication attributes? Check IIS's security settings. Is anonymous authentication enabled? – Panagiotis Kanavos Jun 02 '15 at 11:33
  • @UserControl I made a odata web api using the tutorial on microsoft asp.net site and it worked fine. I have this code on similar lines it doesn't work. Where to see the IIS auth methods ? I guess there must be some place in the code from where this authentication is mandated. I must remove it. – Novak007 Jun 02 '15 at 11:35
  • @PanagiotisKanavos Where should I check IIS's security settings ? – Novak007 Jun 02 '15 at 11:35
  • @UserControl I am using just one function in my controller [HttpGet, EnableQuery] public IQueryable GetRecord(ODataQueryOptions options) – Novak007 Jun 02 '15 at 11:40
  • @Novak007, open Control Panel -> Administrative tools -> Internet Information Server Manager. Then select your site and double click Authentication icon. – UserControl Jun 02 '15 at 11:56
  • @UserControl Thanks, could you suggest why this could be happening ? I ran one similar project that was working and this is asking for authentication. This proj is connected to my local db. – Novak007 Jun 02 '15 at 12:05
  • @Novak007, before a request goes into the managed pipeline it's processed by IIS first. That includes authentication. By default, Anonymous and Windows should be enabled. If it's already enabled it may be another reason (like NTFS permissions or broken ASP.NET registration) but it's hard to say given the input. – UserControl Jun 02 '15 at 12:30

1 Answers1

1

You are getting the authentication window because Chrome is getting back a 401 Unauthorized response when it tries to call the website as you have posted. This can either be caused by the web server rejecting your request based on a lack of authorization (e.g. windows authorization turned on as Novak007 suggests) or by your code explicitly.

Try setting a break point in your project and if you are able to hit it then the problem is not a server config issue but somewhere in your code.

If you are not able to hit your project at all then this is a server configuration issue. Since it looks like you are using IIS Express I would check both your web.config and the application host config file located in \My Documents\IISExpress\config\applicationhost.config to see if windows or some other integrated authentication scheme is enable. See this question for reference on IIS Express IIS Express Windows Authentication

Community
  • 1
  • 1
bechbd
  • 6,206
  • 3
  • 28
  • 47
  • I ran a similar proj on the same machine. so , I guess the problem must be in my code, right ? – Novak007 Jun 02 '15 at 12:43
  • 1
    Without seeing your code it would be hard to say that for sure but it certainly sounds likely that your code is the culprit. You could also run this using IIS instead of IIS Express if you would like to remove that as a variable. Then you can check the authentication settings as UseControls suggests. – bechbd Jun 02 '15 at 12:46
  • Hi, I debugged it and the Request is HTTP Request is reaching the code. – Novak007 Jun 02 '15 at 13:09
  • @bechbcd But not the action function of My controller, it is in fact never going to the aaction function – Novak007 Jun 02 '15 at 13:26
  • Are you sure you are using the correct route? Do you happen to have OWIN installed in your project? – bechbd Jun 02 '15 at 14:52