by aanund
30. January 2011 01:33
Sometimes (often) you need to switch the default EPiServer login page (~/util/login.aspx) with one of your own. And using EPiServer, sometimes you would like to use an EPiServer page (friendly url and all) as the login page. This can pose something of a problem.
This is caused by a combination of the Login control and the AuthenticationConfig (internal static class) which contains a method, that will do a string comparison on FormsAuthentication.LoginUrl and Context.Request.Path (which will be the filename of the page).
To overcome this, you can for instance do…
<asp:Login ID="LoginControl" runat="server" OnLoggedIn="LoggedIn" />
And then in codebehind…
protected void LoggedIn(object sender, EventArgs e)
{
Response.Redirect(GetRedirectUrl(), true);
}
private string GetRedirectUrl()
{
string returnUrl = FormsAuthentication.GetRedirectUrl(string.Empty, false);
if (!string.IsNullOrEmpty(returnUrl))
{
return returnUrl;
}
string str2 = LoginControl.DestinationPageUrl;
if (!string.IsNullOrEmpty(str2))
{
return base.ResolveClientUrl(str2);
}
return FormsAuthentication.DefaultUrl;
}
Now your page will beautifylly redirect.