请求失败,HTTP状态为401:未授权。

时间:2017-10-20 02:17:10

标签: c# asp.net web-services

当我在Windows 10 v1607上调用Web服务时,它对我来说很好,但是当我在Windows 10 v1703上尝试相同的Web服务时,它给了我这个错误:

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

请注意,如果我将Web服务身份验证设置为匿名,则可以正常工作,但从安全角度来看,这是不可接受的。目前,安全设置是asp.net模拟和Windows身份验证。

另外,我有webService.UseDefaultCredentials = true

有人有任何建议吗?

1 个答案:

答案 0 :(得分:1)

好的,发现问题 - Visual Studio解决方案对于网络应用属性Web - > Servers - > IIS Express的值http://localhost:51243可以很好地进行调试,但是当我发布它时会保留这些设置,因此它不能在生产服务器上运行。

要解决此问题,我使用生产网址将其切换为External Host

我仍然觉得有趣的是Windows 10 v1607并不关心这一点,而v1703给出了401错误。