I have a web application that uses the asp.net membership and role providers to allow logins that are members of certain roles to have access to various pages depending on role assignments.
During debugging I'd like the app to log in automatically with a test account, so I can check the functionality of the role assignments, and not have to go through entering credentials on the login page each time. Is there an easy way to do this?
Jeff is right, you can do it trough global.asax method:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if(System.Diagnostics.Debugger.IsAttached && User == null)
{
FormsAuthentication.SetAuthCookie("dmike", false);
}
}
cheers
This code does the job. In Login.aspx's Page_Load event:
Membership.ValidateUser("<userName>", "<password>")
FormsAuthentication.RedirectFromLoginPage("<userName>", True)
MSDN Documentation
Note: Membership
uses the System.Web.Security
reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With