如何使用哈希参数将URL重定向到ASP.net MVC操作 [英] How to redirect to an ASP.net MVC action for url with hash parameter

查看:82
本文介绍了如何使用哈希参数将URL重定向到ASP.net MVC操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.Net core 2.2.我重定向到一个身份服务器实例,然后将其重定向回我的MVC应用程序.重定向回URL的格式为:

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)

我尝试过的事情

我尝试添加带有has标签的新路线,但这似乎是非法的:

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?

推荐答案

您将需要修改对IdentityServer的身份验证请求,以使用response_mode=form_postresponse_mode=query.

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

片段未发送到服务器,如以下定义: https://blog.httpwatch.com/2011/03/01/6-things-you-should-know-about-fragment-urls/. 当您希望前端JavaScript捕获令牌时,将使用片段响应模式.

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.

这篇关于如何使用哈希参数将URL重定向到ASP.net MVC操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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