我目前正在熟悉MVC框架和Azure B2C登录/凭证。目标是将示例项目中提供的一些逻辑实现到现有项目中。在详细介绍我在自己的项目中遇到的问题之前,我不能弄清楚以下几点:
提供的示例应用程序(参见https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi)包含一个类AuthController.cs,该类提供用于登录/注销等的逻辑。AuthController中的方法似乎是在使用部分视图_LoginPartial时调用的,例如
@if (Request.IsAuthenticated)
else
{
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Sign up / Sign in", "SignUpSignIn", "Account", routeValues: null, htmlAttributes: new { id = "signUpSignInLink" })</li>
</ul>
}AccountController中的登录方法接受参数string redirectUrl,例如
public void SignUpSignIn(string redirectUrl)
{
redirectUrl = redirectUrl ?? "/";
// Use the default policy to process the sign up / sign in flow
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = redirectUrl });
return;
}现在,控制器在调试时似乎是不可访问的,因此我无法确定参数redirectUrl是从哪里传入的。这背后的原因是我想在一个已经存在的控制器类中实现SignUpSignIn方法。分部类和控制器之间的关系是什么?我从哪里获得这个redirectUrl?如果我的问题看起来微不足道,我很抱歉,但我目前正在从经典的ASP.NET过渡到MVC。
发布于 2019-11-01 16:06:09
你需要在应用程序的AAD注册中将托管应用程序的主域名配置为回复URL,并在重定向到AAD时将其作为redirect_uri传递,以允许用户登录。
AAD只会将访问令牌重定向到在AAD中的应用程序注册中指定为回复URL的URL。
因此,在本例中,redirectUrl被设置为"https://localhost:44316/“。控制器从web.config文件中获取redirectUrl值。
它必须与Azure AD中配置的回复URL匹配。
https://stackoverflow.com/questions/58641928
复制相似问题