【发布时间】:2010-08-11 15:32:10
【问题描述】:
目前我有一个使用UserNamePasswordValidator 来验证客户端用户的服务。验证代码如下:
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?
}
}
任何帮助将不胜感激。
【问题讨论】:
标签: c# wcf validation authentication operationcontract