目前我有一个使用 aUserNamePasswordValidator
来验证客户端用户的服务。验证代码如下:
public override void Validate(String userName, String password)
{
if (userName == null) || (password == null)
throw new FaultException("Username and/or password not specified.");
if (userName != "test") && (password != "tset")
throw new FaultException("Invalid username and/or password.");
}
如您所见,当出现问题时,代码总是会抛出异常。
现在的问题 - 有什么理由我应该检查ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated
我的函数内部是否为真OperationContract
?例如,
public interface IMyService
{
[OperationContract]
void myOpContract();
}
public class MyService : IMyService
{
public void myOpContract()
{
// Do I really need this conditional statement?
if (ServiceSecurityContext.Current.PrimaryIdentity.IsAuthenticated)
// Proceed as expected
else
// Fail?
}
}
任何帮助将不胜感激。