问题
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