如何为WCF服务配置.NET授权规则 [英] How to configure .NET authorisation Rules for WCF service
问题描述
Web配置
< 授权 >
< allow users = Bob / >
< deny users = ? / >
< / authorization >
WCF客户:
string username = Bob;
string password = password跨度>;
bool bLogin = false ;
// 在app.config文件中提供BasicHttpBinding和端点。
AuthenticationServiceClient authService = new AuthenticationServiceClient();
string customCredential = 未使用默认会员提供者。;
// 身份验证票证在各会话期间保持有效。
< span class =code-keyword> bool isPersistent = true ;
bLogin = authService.Login(用户名,密码,customCredential,isPersistent);
Global.asax:
protected void Application_Start( object sender,EventArgs e)
{
System.Web.ApplicationServices.AuthenticationService.Authenticating + =
new EventHandler< System.Web.ApplicationServices.AuthenticatingEventArgs> (AuthenticationService_Authenticating);
}
void AuthenticationService_Authenticating( object sender,System.Web .ApplicationServices.AuthenticatingEventArgs e)
{
if (e.UserName.IndexOf( Bob)> = 0 )
{
e.Authenticated = true ;
}
e.AuthenticationIsComplete = true ;
}
因此,当我从Web配置文件中删除拒绝匿名用户时,我点击了Global.asax中的AuthenticationService_Authenticating文件,但当我将其添加回来时,我获得拒绝访问权限。我只是希望它在我的设置中缺少一些小东西。如果我不清楚,请询问,我会再详细说明。
提前谢谢。
Hey I'm just wondering if anyone can help me out. I need to configure my web site to deny all anonymous users apart from one specific user.
Web Config
<authorization>
<allow users="Bob" />
<deny users="?"/>
</authorization>
WCF Client :
string username = "Bob";
string password = "password";
bool bLogin = false;
// BasicHttpBinding and endpoint are provided in app.config file.
AuthenticationServiceClient authService = new AuthenticationServiceClient();
string customCredential = "Not used by the default membership provider.";
// Authentication ticket remains valid across sessions.
bool isPersistent = true;
bLogin = authService.Login(username, password, customCredential, isPersistent);
Global.asax:
protected void Application_Start(object sender, EventArgs e)
{
System.Web.ApplicationServices.AuthenticationService.Authenticating +=
new EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs> (AuthenticationService_Authenticating);
}
void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
{
if (e.UserName.IndexOf("Bob") >= 0)
{
e.Authenticated = true;
}
e.AuthenticationIsComplete = true;
}
So when I remove the deny anonymous users from the web config file I hit the AuthenticationService_Authenticating in the Global.asax file but when I add it back in I get access denied. I'm just hoping it's something small that I am missing in my setup. If I'm not being clear please ask and I will try elaborate a bit more.
Thanks in advance.
这篇关于如何为WCF服务配置.NET授权规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!