How to redirect to an ASP.net MVC action for url with hash parameter

泄露秘密 提交于 2020-04-18 05:46:15

问题


I am using ASP.Net core 2.2. I redirect to an identity server instance, which then redirects back to my MVC app. The redirect back url is of the form:

http://localhost:8081/home/fetchtokenresponse#id_token=longtokenvalue&token_type=Bearer&expires_in=3600&scope=myscopes&session_state=jizlw_6DiGhYvkGk6fKRKkhZQoFlYKJ5v1_2Lwd-caI.MN0g0HwpGuulkwKleHtJCg

In my action I want to be able to read the parameters like

public IActionResult FetchTokenResponse(string id_token)

What I have tried

I tried adding a new route with a has tag, but this appears to be illegal:

routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}#{id?}");

Is there another way to intercept the path and redirect to my action?


回答1:


You will need to modify your authentication request to IdentityServer to use response_mode=form_post or response_mode=query.

Fragments are not sent to the server, as defined in: https://blog.httpwatch.com/2011/03/01/6-things-you-should-know-about-fragment-urls/. Fragment response mode is used when you want your front-end JavaScript to grab the tokens.



来源:https://stackoverflow.com/questions/60741767/how-to-redirect-to-an-asp-net-mvc-action-for-url-with-hash-parameter

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