Click here to Skip to main content
15,886,793 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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
XML
<authorization>
  <allow users="Bob" />
  <deny users="?"/>
</authorization>


WCF Client :

C#
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:
C#
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.
Posted
Updated 13-Apr-14 10:58am
v3
Comments
Sergey Alexandrovich Kryukov 13-Apr-14 16:07pm    
Probably you mean WCF... :-)
—SA
frostcox 13-Apr-14 16:58pm    
That I do:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900