C# 因此,当一个用户登录到我的应用程序时,所有当前用户都成为该用户
我正在试图找出我的程序的哪个部分导致了这个错误 我有多个页面都是从C# 因此,当一个用户登录到我的应用程序时,所有当前用户都成为该用户,c#,asp.net,C#,Asp.net,我正在试图找出我的程序的哪个部分导致了这个错误 我有多个页面都是从PageBase继承的。他们从PageBase获取用户配置文件。这是从PageBase获取其用户名的函数: uiProfile = ProfileManager.FindProfilesByUserName(CompanyHttpApplication.Current.Profile.UserName) 在公司的应用程序中我有 public static CompanyHttpApplication Current
PageBase
继承的。他们从PageBase
获取用户配置文件。这是从PageBase
获取其用户名的函数:
uiProfile = ProfileManager.FindProfilesByUserName(CompanyHttpApplication.Current.Profile.UserName)
在公司的应用程序中
我有
public static CompanyHttpApplication Current
{
get { return (CompanyHttpApplication)HttpContext.Current.ApplicationInstance; }
}
及
public CompanyProfileInfo配置文件
{
收到
{
返回配置文件??
(简介)=
ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.Authenticated,
User.Identity.Name).Cast
().ToList().First());
}
私有集{profile=value;}
}
不幸的是,我没有编写这段代码,而编写这段代码的程序员已经不在项目中了。是否有人可以向我解释为什么当另一个用户登录时(当我使用应用程序时),我会成为该用户?HttpContext.Current.ApplicationInstance是全局共享的。它不是针对每个用户的。因此,您拥有一个共享配置文件,当新用户登录时,该配置文件将立即覆盖您最初设置的内容。应用程序实例将在每个请求(应用程序级别)之间共享 您需要会话级别—每个用户都有自己的实例 使用而不是 (下面的代码重命名了original,并添加了一个属性,使其更加清晰。如有必要,请随意调整。)
这是wep应用程序吗。。?如果是这样,您需要获取Page.UserIdentity.Name.Split(\”)创建一个字符串[]将其分配给该字符串,并询问原始作者。同意+1。op可以尝试将当前HttpContext的User.Identity.Name而不是HttpApplication.current.Profile.UserName传递到FindProfilesByUserNameRoger中。谢谢我不太清楚所有这些东西是如何工作的(我对ASP.net还相当陌生),但我会确保对其进行更改,并希望在这个过程中了解更多关于它的信息这对我来说很有用。谢谢你花时间回答我的问题
public CompanyProfileInfo Profile
{
get
{
return profile ??
(profile =
ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.Authenticated,
User.Identity.Name).Cast
<CompanyProfileInfo>().ToList().First());
}
private set { profile = value; }
}
public static CompanyHttpApplication CurrentApplication
{
// store application constants, active user counts, message of the day, and other things all users can see
get { return (CompanyHttpApplication)HttpContext.Current.ApplicationInstance; }
}
public static Session CurrentSession
{
// store information for a single user — each user gets their own instance and can *not* see other users' sessions
get { return HttpContext.Current.Session; }
}