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
The FormsAuthentication.RedirectFromLoginPage uses the defaultUrl to decide where to redirect after login. So make sure, you have a valid url other than your LoginPage.aspx defined.
FormsAuthentication.RedirectFromLoginPage("userName", True);
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx"
...
defaultUrl="~/AnyFolder/PageAfterLogin.aspx"
... />
</authentication>
I hope this helps a bit.
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.
As an alternative there exists also tools like Selenium IDE which is a plugin for Firefox. Its main purpose is to provide some kind of testing for UIs. For this purpose you can record actions that are done on the UI. What you could do is to record the credentials you enter for the test-user once and save them. The next time you come back, you execute the script which automatically fills in the necessary information.
There are other tools which are specialized for the purpose of auto-filling a form on a webpage. Selenium is more thought as a testing evironment, but I've also used it for such purposes. Of course this is just a workaround.
In the page_load event you can use FormsAuthentication.SetAuthCookie:
FormsAuthentication.SetAuthCookie("username", false);
In the Application_AuthenticateRequest method (aka the Applications AuthenticateRequest event) in the global.asax file, add code that checks if you are running the site within the debugger (something like system.Diagnostics.Debugger.IsAttached) and, if you are, have it create the login ticket, create the cookie and attach it to the session. The FormsAuthentication library provides what you need if hte membership provder doesn't have it.
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