【问题标题】:How do I access the credentials in web service that the user has set while calling the webservice?如何访问用户在调用 Web 服务时设置的 Web 服务中的凭据?
【发布时间】:2019-09-26 13:31:04
【问题描述】:

我有一个网络服务,例如

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class SI_C : System.Web.Services.WebService {

public SI_C()
{

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

[Webmethod]

public bool CreateRecord(classname objname) //some class I am setting the data to
{
   //Creates a record.
}
}

现在在我创建的客户端消费时

 SI_C_In_SoapClient client = new SI_C_In_SoapClient("SI_C");
 client.ClientCredentials.UserName.UserName = "Username Sent";
 client.ClientCredentials.UserName.Password = "Passport Sent";

现在我想在我的网络服务中访问这个发送的密码和用户名。我该怎么做?

更新:

  1. 使用网络凭据调用在客户端设置密码和用户名
  2. 在网络服务中接收
  3. 发送到数据库并检查是否正常?就是这样。

【问题讨论】:

    标签: c# asp.net soap asmx soap-client


    【解决方案1】:

    这主要取决于您如何配置网络服务器应用程序。如果使用 IIS,那么这个问题的答案完全取决于您如何设置安全性。

    查看HttpContext.Current.UserCredentialCache.DefaultNetworkCredentials 这是链接:

    分别:

    How does HttpContext.Current.User.Identity.Name know which usernames exist?

    https://docs.microsoft.com/en-us/dotnet/api/system.net.credentialcache.defaultnetworkcredentials?redirectedfrom=MSDN&view=netframework-4.8#System_Net_CredentialCache_DefaultNetworkCredentials

    【讨论】:

    • 我只想在调用之前访问客户端应用程序中设置的 Web 服务中的凭据。
    • 您是否使用集成安全性?您需要详细说明如何在 Web 服务器上配置安全性。如果安全设置为集成,那么HttpContext.Current.User 就是您要查找的内容。
    • 我将根据数据库检查用户名和密码。
    • 1.使用网络凭据调用在客户端设置密码和用户名 2. 在 web 服务中接收 3. 发送到数据库并检查是否正常?就是这样。
    • 我不明白你在说什么。没有意义。
    猜你喜欢
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多