Retain Url Fragment within ReturnUrl in Forms Authentation under MVC

流过昼夜 提交于 2019-12-08 02:18:37

问题


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.

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

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.


回答1:


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

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.

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

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


来源:https://stackoverflow.com/questions/7270066/retain-url-fragment-within-returnurl-in-forms-authentation-under-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!