在MVC下以表单身份验证在ReturnUrl中保留URL片段 [英] Retain Url Fragment within ReturnUrl in Forms Authentation under MVC

查看:81
本文介绍了在MVC下以表单身份验证在ReturnUrl中保留URL片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要将用户发送到登录页面,并使用他们当前位于包括网址片段的页面填充returnurl参数,以便他们完成操作登录后,他们将被重定向回到其原始页面,并且该页面向下滚动到特定的#location.

I have a scenario where I need to send the user to the login page, with the returnurl parameter populated with the page they're currently sitting on including a url fragment, so as when they complete login, they're redirected back to their original page and the page scrolls down to a specific #location.

目前,除了returnUrl参数到达Login ActionMethod时url片段丢失之外,其他所有操作都有效.

At present, it's all working except that the url fragment is lost when the returnUrl param reaches the Login ActionMethod.

是否可以保留此url片段,以使其在登录阶段不会丢失?我可以在登录页面的网址中看到#fragment,但是当我在登录方法中查看'returnUrl'的值时,它似乎被剥夺了.

Is there a way to retain this url fragment so it doesn't get lost during the login phase? I can see the #fragment in the url on the login page, but it appears to be stripped off when I look at the value of 'returnUrl' in my login method.

推荐答案

是否可以保留此url片段,以使其在登录阶段不会丢失?

Is there a way to retain this url fragment so it doesn't get lost during the login phase?

不,没有. url片段永远不会发送到服务器.一种可能是在将客户端传递的returnUrl传递给服务器之前对其进行修改,以使url片段成为查询字符串的一部分.然后,当登录成功并且服务器需要重定向回returnUrl时,它将对其进行修改为原始值.

No, there isn't. The url fragment is never sent to the server. One possibility is to modify the returnUrl on the client before passing it to the server so that the url fragment becomes part of the query string. Then when the login succeeds and the server needs to redirect back to the returnUrl it would modify it to the original value.

例如,在将其发送到Login方法之前,它可能看起来像这样:

For example it might look like this before sending it to the Login method:

http://example.com/admin/index?fragment=somefragment

这篇关于在MVC下以表单身份验证在ReturnUrl中保留URL片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆