简体   繁体   中英

My web application is rejecting Windows authentication for a local Windows account

My issue is that my service only lets my own Windows account connect to it, but I would like to allow connections from any valid Windows domain accounts. My service is hosted in IIS Express. When I browse to https://localhost:44300/FileRetrievalService.svc/get in Google Chrome, I see my [WebGet] method is called just fine. When I try to create a web request to it, it also works, as long as I specify my own Windows user account:

WebRequest request = WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add("Path", filePath);
request.Credentials = new NetworkCredential("username", "password", "localhost");
return request.GetResponse();

When I try specifying a different local Windows account on my machine to authenticate a user against my service by changing "username" and "password" in the above code to another account which I know for sure exists on my machine, I get the following error:

System.Net.WebException: The remote server returned an error: (401) Unauthorized.

I have the following in my service's 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>

What is the cause of this issue?

I'm going to guess your account has admin priveleges, and the other account does not. If that's the case, you need to explicitly give permissions to your project folder (ie using Windows Explorer) or assign that user to a group that already has permission.

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