简体   繁体   中英

The request failed with HTTP status 401: Unauthorized.

When I am calling a web service on Windows 10 v1607 it works fine for me, but when I try the same web service on Windows 10 v1703, it gives me this error:

The request failed with HTTP status 401: Unauthorized. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[WebException: The request failed with HTTP status 401: Unauthorized.]
   System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +237136
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +267
   CPR.Apps.CPMS.ServiceWrapper.CPMSProxy.CPMSService.GetUserGroupTasks(User& user) +138
   CPR.Apps.CPMS.ServiceWrapper.WebAppServiceWrapper.GetUserGroupTasks(User& cpmsUser) +111
   CCPS.App.Web.UI.Global.Session_Start(Object sender, EventArgs e) +145
   System.Web.SessionState.SessionStateModule.CompleteAcquireState() +380
   System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +1250
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +631
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

Please note that it works if I set the web service authentication to be anonymous, but this is not acceptable from a security standpoint. Presently, the security settings are asp.net impersonation and windows authentication.

Also, I have webService.UseDefaultCredentials = true .

Does anyone have any suggestions?

OK, found the problem--the Visual Studio solution had for the web app properties Web -> Servers -> IIS Express with a value like http://localhost:51243 which works fine for debugging, but when I publish it keeps those settings so it will not work on the production server.

To resolve the issue, I switched it to External Host with the production URL.

I still find it interesting that Windows 10 v1607 doesn't care about this while v1703 gives the 401 error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM