表单身份验证可以忽略 returnUrl

发布于 2024-11-06 21:19:18 字数 126 浏览 0 评论 0原文

有没有一种简单的方法可以让表单身份验证忽略 returnURL?

因此,用户单击链接,网站超时,他们被重定向到我的登录页面(将 ReturnUrl 附加到 URL) - 我不希望发生这种情况,或者当他们再次登录时它被忽略。

Is there an easy way to get forms authentication to ignore the returnURL?

So the user clicks 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别把无礼当个性 2024-11-13 21:19:18

如果你不想展示的话,可以把它撕下来。我这样做是因为我不希望它显示我设置的 SEO 友好 URL。

Global.asax 文件中输入以下内容:

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

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
岁月苍老的讽刺 2024-11-13 21:19:18

一种选择是在登录表单的代码隐藏中添加一些执行以下操作的代码:

if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
{
    Response.Redirect("path/to/my/login.aspx");
}

换句话说,检查登录页面是否存在 returnUrl 查询字符串参数,如果存在,则通过重定向回您自己来将其删除。

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.

匿名的好友 2024-11-13 21:19:18

我认为在使用表单身份验证时,您无法阻止将其附加到 URL 上。

但是,您不需要调用RedirectFromLoginPage (这就是我假设你现在正在做的事情);您只需使用 SetAuthCookie保留登录状态和响应。之后重定向任何您喜欢的地方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文