Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在服务器端检查OperationContext的凭据.UserName_.net_Wcf - Fatal编程技术网

.net 在服务器端检查OperationContext的凭据.UserName

.net 在服务器端检查OperationContext的凭据.UserName,.net,wcf,.net,Wcf,是否可以通过以下代码获取客户端提供的用户名和密码: myChannelFactory.Credentials.UserName.UserName = "username"; myChannelFactory.Credentials.UserName.Password = "password"; 在服务器端代码中?特别是在这种方法中: public class MyAuthorizationManager : ServiceAuthorizationManager { protected

是否可以通过以下代码获取客户端提供的用户名和密码:

myChannelFactory.Credentials.UserName.UserName = "username";
myChannelFactory.Credentials.UserName.Password = "password";
在服务器端代码中?特别是在这种方法中:

public class MyAuthorizationManager : ServiceAuthorizationManager
{
    protected override bool CheckAccessCore(OperationContext operationContext)
    {
    }
}

编写一个从UserNamePasswordValidator派生的类,然后将其与WCF服务行为定义一起使用

重写类中的“验证(字符串用户名、字符串密码)”

然后web(app).config如下所示:

<behaviors>
  <serviceBehaviors>
    <behavior name="ClearServiceBehaviour">
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
            customUserNamePasswordValidatorType="MyNamespace.MyCustomUserPassAuthenticator, MyAssembly" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>


您需要如何处理用户名和密码?是否执行自定义验证?是。在ServiceAuthorizationmanager中执行此操作的逻辑是,我希望对登录Windows域的用户执行传统检查。(我知道我可以-在简单的情况下-为wcf身份验证创建自定义验证器)您需要的不仅仅是检查用户是否经过身份验证以及是否具有特定的角色吗?我担心它不会起作用,因为在授权期间,用户已经过了身份验证=验证了凭据并设置了身份。这太糟糕了。我的问题很简单,我只是希望我的用户能够方便地使用应用程序。我会让他以“单点登录”的方式登录,因为他已经在域中,或者我会询问他用户名+密码。是的,我知道这个类,但问题是我还需要检查WindowsCredentials(以防用户在域中注册)。关键是我需要在CheckAccesscore方法中获得用户名和密码,用户名和密码在operationContext中是确定的,我只是不知道如何获得它们。