【发布时间】:2020-08-07 14:20:25
【问题描述】:
我有一个 .NET Core 3.1 Web 应用程序,带有使用 Windows 身份验证的 React。 当用户输入他们的 Active Directory 凭据时,我想在允许访问 React 应用程序之前验证他们是否属于特定的 Active Directory 组。
我尝试将默认端点设置为登录控制器以验证用户的组,但如果他们确实有有效的组,我不知道如何重定向到 React 应用程序。
Startup.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}",
defaults: new { Controller = "Login", action = "Index" });
});
登录控制器:
public IActionResult Index()
{
if (HttpContext.User.Identity.IsAuthenticated)
{
string[] domainAndUserName = HttpContext.User.Identity.Name.Split('\\');
//AuthenticateUser verifies if the user is in the correct Active Directory group
if (AuthenticateUser(domainAndUserName[0], domainAndUserName[1]))
{
//This is where i would like to redirect to the React app
return Ok(); //This does not go to the react app
return LocalRedirect("http://localhost:50296/"); //This will keep coming back to this method
}
return BadRequest();
}
}
是否可以从控制器重定向到 React 应用程序? 有没有更好的方法来验证活动目录组,可能是通过 authorizationService.js?
【问题讨论】:
-
您可以在授权过滤器中处理它。
-
您能否提供任何细节或链接,以帮助我找到正确的方向?
-
代替 return LocalRedirect(string),使用 return Page() 或 return RedirectToPage("/Index") 或任何您的默认页面。
-
不。我上面错了。我认为这条线应该为你做 :)
return RedirectPermanent("http://localhost:50296/");
标签: reactjs asp.net-core