【问题标题】:The request failed with HTTP status 401: Unauthorized.请求失败,HTTP 状态为 401:未授权。
【发布时间】:2017-10-20 02:17:10
【问题描述】:

当我在 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

有人有什么建议吗?

【问题讨论】:

    标签: c# asp.net web-services


    【解决方案1】:

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

    为解决此问题,我将其切换为 External Host 并使用生产 URL。

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

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 1970-01-01
      • 2012-06-30
      • 2013-01-01
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 2012-05-03
      相关资源
      最近更新 更多