[英]my web application connect with database from one windows user account but not with second windows user account
[英]My web application is rejecting Windows authentication for a local Windows account
我的問題是我的服務僅允許我自己的Windows帳戶連接到它,但是我想允許來自任何有效Windows域帳戶的連接。 我的服務托管在IIS Express中。 當我在Google Chrome瀏覽器中瀏覽到https://localhost:44300/FileRetrievalService.svc/get
時,我看到了[WebGet]
方法就可以了。 當我嘗試為其創建Web請求時,只要指定了自己的Windows用戶帳戶,該請求也將起作用:
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add("Path", filePath);
request.Credentials = new NetworkCredential("username", "password", "localhost");
return request.GetResponse();
當我嘗試在計算機上指定其他本地Windows帳戶以通過將上述代碼中的"username"
和"password"
更改為我確定在計算機上確實存在的另一個帳戶來針對我的服務對用戶進行身份驗證時,出現以下錯誤:
System.Net.WebException:遠程服務器返回錯誤:(401)未經授權。
我在服務的Web.config
具有以下內容:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithTransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="FileRetrievalPoCV3.FileRetrievalService">
<endpoint behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithTransportSecurity" contract="FileRetrievalPoCV3.IFileRetrieval" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="false"/>
</system.webServer>
</configuration>
此問題的原因是什么?
我猜您的帳戶具有管理員權限,而另一個帳戶則沒有。 在這種情況下,您需要顯式授予項目文件夾的權限(即使用Windows資源管理器)或將該用戶分配給已經具有權限的組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.