I am making a Http Module for authentication in my web application in asp.net 2.0. When the AuthticateRequest event is fired then I get the userid and password values from current request. But Every time I am getting null in both. My code is here
namespace Business.YouBecome
{
class LoginModuleYouBecome : IHttpModule
{
public void Init(HttpApplication httpApplication)
{
httpApplication.AuthenticateRequest += new EventHandler(httpApplication_AuthenticateRequest);
// httpApplication.AuthorizeRequest += new EventHandler(httpApplication_AuthorizeRequest);
}
void httpApplication_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = (HttpContext)application.Context;
clsLogin login = new clsLogin();
login.UserName = application.Request["txtuser"];
login.Password = application.Request["txtpass"];
//throw new NotImplementedException();
}
public void Dispose() { }
}
}
I have this class in a class library project and added the code in web.config.
Please suggest me where I am doing wrong. Thanks in advance.
try like this: in your event handler you should check if your user is authenticated and then use User.Identity to access name and password.