Can forms authentication ignore returnUrl
Is there an easy way to get forms authentication to ignore the returnURL?
So the user cl开发者_如何学Cicks a link, the site timesout, they get redirected to my login page (which appends ReturnUrl to the URL) - I don't want this to happen, or for it to be ignored when they login again.
You can strip it off if you don't want to show it. I do that because I don't want it to show with SEO-friendly URLs that I have setup.
In the Global.asax
file put the following:
Protected Sub Application_EndRequest(sender As Object, e As System.EventArgs)
Dim redirectUrl As String = Me.Response.RedirectLocation
If Not Me.Request.RawUrl.Contains("ReturnUrl=") AndAlso Not String.IsNullOrEmpty(redirectUrl) Then
Me.Response.RedirectLocation = Regex.Replace(redirectUrl, "\?ReturnUrl=(?'url'[^&]*)", String.Empty)
End If
End Sub
One option is to have some code in your login form's code-behind that does the following:
if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
{
Response.Redirect("path/to/my/login.aspx");
}
In other words, check in your login page for the presence of the returnUrl querystring parameter and if it's present, strip it out by redirecting back to yourself.
I don't think you can prevent this from being tacked onto the URL when using Forms Authentication.
However, you don't need to call RedirectFromLoginPage
(which is what I'll presume you're doing at the minute); what you can do is simply use SetAuthCookie
to persist the login state and Response.Redirect
anywhere you like after that.
精彩评论