NetworkCredential UseDefaultCredentials not working

后端 未结 1 708
长情又很酷
长情又很酷 2021-01-18 01:39

We wrote a code long back to call a service with domain credentials. Now domains are changed and planning to use default Windows Account

So I am trying to reset Netw

相关标签:
1条回答
  • 2021-01-18 02:20

    If I understood you correctly then I think you need to add keys for your Account, User Name and Password under appSettings in the config file.

    <appSettings>
        <add key="YourDomain" value="yourAccount"/>
        <add key="UserName" value="yourAccount"/>
        <add key="Password" value="yourAccount"/>
    </appSettings>
    

    After that in your code,

    EmployeeService prxy = new EmployeeService();
    prxy.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["UserName"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(), System.Configuration.ConfigurationManager.AppSettings["YourDomain"].ToString());
     //while debug, prxy.UseDefaultCredentials= false here
    //My soap extension gets executed and resets credentials.
    prxy.GetEmployee(empId);
    
    0 讨论(0)
提交回复
热议问题