我刚接触过aspnet core 2.0,我想完成的是将尚未完成个人资料的用户重定向到他们可以完成的页面。我正在使用默认模板进行Identity server的用户身份验证。
我曾尝试使用中间件,但我重定向到的页面显示为空白。这是最好的方法吗?或者有人能帮助它工作吗。这是我的中间件。
public class FarmProfileMiddleware
{
private readonly RequestDelegate next;
public FarmProfileMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context, UserManager<ApplicationUser> userManager)
{
var user = await userManager.GetUserAsync(context.User);
if (user != null)
{
if (!user.EmailConfirmed && !context.Request.Path.ToString().Contains("profile"))
{
var url = context.Request.PathBase + "/Users/Profile";
context.Response.Redirect(url);
}
}
else
{
await next(context);
}
}
}
提前谢谢。