Database connection in WCF using dedicated system account stored in IIS server's registry

StackOverflow https://stackoverflow.com/questions/21265515

  •  30-09-2022
  •  | 
  •  

문제

I have WCF Service project which connect to the SQL server 2008 to do operation like Insert, Update, Delete and select. On IIS I want the connection to sql server is made by using dedicated system account which is stored in server's registry. I am using following code in my WCF web.config to get userID and Passward from server's registry

<System.web>
<identity impersonate="true"      userName="registry:HKLM\SOFTWARE\MY_SECURE_APP\acctopsmain\ASPNET_SETREG,userName" password="registry:HKLM\SOFTWARE\MY_SECURE_APP\acctopsmain\ASPNET_SETREG,password" />
</system.web>

I am getting login failed for User "Domain\ServerName" error message

Authentication level on IIS server is Anonymous Authentication

Any help would be appreciated. Thanks, Yogi

도움이 되었습니까?

해결책

I don't know whether is a good approach or not, however I used the following steps to resolve my issue.

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="True">
    </serviceHostingEnvironment>
    <services>
      <service name="Service" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="IService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          ........some othere setting
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Add I under the system.web I use the following code

<system.web>
   <authorization>
        <allow users="?"/>
      </authorization>
  <identity impersonate="true"      userName="registry:HKLM\SOFTWARE\MY_SECURE_APP\acctopsmain\ASPNET_SETREG,userName" password="registry:HKLM\SOFTWARE\MY_SECURE_APP\acctopsmain\ASPNET_SETREG,password" />
</system.web> 

on Service.vb class I added

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _
Public Class Service Implements IService
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top