登录重定向后如何传递用户名? [英] How to pass username after login redirect?
问题描述
我有2个应用程序:一个进行登录( app1 ),另一个进行我想要的其他操作( app2 ). app1 是内置于ASP.NET Boilerplate中的,我要做的是在使用该应用程序登录后,我想重定向到 app2 .到目前为止,一切都很好,我只是使用returnUrl
参数重定向到 app2 .问题是我想将某些登录信息(例如username
)传递给 app2 .不应更改 app1 中的任何内容,那么我该怎么做?
I have 2 applications: one does the login (app1) and another one does other stuff that I want (app2). The app1 is built in ASP.NET Boilerplate and what I want to do is after login with this app, I want to redirect to the app2. Until now everything is fine, I just used the returnUrl
parameter to redirect to the app2. The problem is that I want to pass to app2 some of the login information like username
. It's not supposed to change anything in app1, so how can I do that?
app1 和 app2 都是在MVC 5中构建的.
Both app1 and app2 are built in MVC 5.
推荐答案
在 app1 中,您可以从loginResult.User
访问该用户,正如您在
In app1, the user is available from loginResult.User
as you can see in this line:
await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe);
您可以在选中returnUrl
后将username
作为查询参数附加:
You can append the username
as a query parameter after checking returnUrl
:
if (string.IsNullOrWhiteSpace(returnUrl))
{
returnUrl = Request.ApplicationPath;
}
else
{
returnUrl += "?username=" + loginResult.User.UserName; // This line
}
并在 app2 中进行检索.
这篇关于登录重定向后如何传递用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!