How to set Azure Authentication custom login return url?(如何设置 Azure Authentication 自定义登录返回 url?)
问题描述
我关注了这篇文章 https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/ 为我的 MVC 应用程序设置 Azure 身份验证.首先,我打开了 Azure AD 提供程序.在身份验证/授权设置中,我为请求未通过身份验证时采取的操作"选择了允许请求(无操作)",因为我只需要用户登录某些控制器操作.
I followed this article https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/ to set up Azure authentication for my MVC app. First I turned on Azure AD provider. In the Authentication / Authorization settings, I selected "Allow request(no Action)" for "Action to take when request is not authenticated" because I only need users to login for certain controller actions.
然后我添加了一个自定义 FilterAttribute 来检查一个操作是否需要身份验证,如 https://stackoverflow.com/a/26652816/1837339.在 OnAuthenticationChallenge 函数中,我将这段代码重定向到登录页面:
Then I added a custom FilterAttribute to check if one action needs authentication as in https://stackoverflow.com/a/26652816/1837339. In the OnAuthenticationChallenge function, I had this code to redirect to login page:
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
if (filterContext.Result is HttpUnauthorizedResult) {
filterContext.Result = new RedirectResult("~/.auth/login/aad");
}
}
所有这些都有效,除了用户完成身份验证后,它会被重定向回 mysite/.auth/login/done 页面,显示您已成功登录"和一个返回我网站的基本 URL 的按钮.
All of this works, except after user finished authentication, it is redirected back to mysite/.auth/login/done page saying "You have successfully signed in" and a button to return to my site's base url.
我想要的是重定向回到用户的原始 url,所以我想我需要以某种方式为登录重定向设置返回 url.但我找不到任何关于此的文档.谁能给点建议?
What I want is the redirection goes back to the user's original url, so I think I need somehow set the return url for the login redirect. But I couldn't find any documentation about this. Anyone could give any advice?
推荐答案
您可以使用 post_login_redirect_url 查询字符串参数来执行此操作.
You can use the post_login_redirect_url query string parameter to do this.
例如,如果您想在用户登录后自动导航到 /welcome.html,您可以将登录重定向设置为 ~/.auth/login/aad?post_login_redirect_url=/welcome.html,用户将被重定向到此页面而不是通用欢迎页面.
For example, if you want to automatically navigate the user to /welcome.html after logging in, you can set your login redirect to ~/.auth/login/aad?post_login_redirect_url=/welcome.html, and the user will be redirected to this page instead of the generic welcome page.
这篇关于如何设置 Azure Authentication 自定义登录返回 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何设置 Azure Authentication 自定义登录返回 url?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01