Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers

$
0
0

I am using ASP.NET MVC4 and calling a method within a controller from one MVC4 project to another, using PostAsync.  I am not using any authentication attribute within the called controller or method.

Referencing this link: [link][1]   [1]: https://stackoverflow.com/questions/16573145/asp-net-mvc-4-401-access-deniedhttp://

Fixed my issue when running application locally and calling PostAsync to application on server. Now, when I deploy the application to the server and try to call the other application I get the unauthorized error. What am I doing wrong?

Both application running in IIS are using the same site, and the same application pool.

Using remote debugging, this is the server response:

    {StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:     {       Cache-Control: private       Server: Microsoft-IIS/7.0       WWW-Authenticate: Negotiate       WWW-Authenticate: NTLM       X-Powered-By: ASP.NET       Date: Fri, 23 Jun 2017 13:44:19 GMT       Content-Length: 6644       Content-Type: text/html; charset=utf-8     }}

And this is my code:

using (var handler = new HttpClientHandler { UseDefaultCredentials = true })
using (HttpClient client = new HttpClient(handler) { BaseAddress = new Uri(Properties.Settings.Default.EnvironmentRootPath)})
{
  List<string> orderNumbers = NumList;
   var pairs = new List<KeyValuePair<string, string>>
   {
     new KeyValuePair<string, string>("orderNumbers", string.Join(",", orderNumbers))                 };
     var content = new FormUrlEncodedContent(pairs);
     var response = client.PostAsync("CentralBroadcast/broadcastNewOrder", content).Result;

if (response.IsSuccessStatusCode)
{                     //
}
else
{                     //
}

Application Pool is using Network for Identity.


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>