在 VS2010 中,我在同一个解决方案中有两个基于 MVC 2 的 Web 应用程序,它们也共享一个公共安装项目。一个应用程序是一种配置实用程序,用于在对方应用程序中设置用户和变量。安装后,两个 IIS 目录在用户浏览器上如下所示: App1: http://localhost/App1/Auth/Login App2: http://localhost/App1/App2/Auth/Login
我遇到的问题是,当用户同时打开两个应用程序并注销其中一个应用程序时,他们也会从对方应用程序中注销。这是一个小问题,但我的任务是纠正它。
据我所知,这两个应用程序必须共享同一个 Session 对象,因为每个控制器中的注销命令方法都会调用 Session.Abandon() 。
只有两个控制器能够注销用户;这是来自这些控制器的构造函数:
App1:命名空间 App1.Controllers
/// <summary>
/// Functionality related to Assets
/// </summary>
public class AssetsController : Controller
{
private IConfig _config = null;
private IProfileRepository _profiles = null;
private IInspectionRepository _inspections = null;
private ICustomLabelsFactory _labels = null;
private IValidateRepository _validator = null;
/// <summary>
/// Create an instance of the AssetsController which uses the db.
/// </summary>
public AssetsController() : this(Config.Current, new ProfileRepository(Config.Current), new InspectionRepository(), new CustomLabelFactory(), new ValidateRepository()) { }
/// <summary>
/// Create an instance of the AssetsController with the given
/// IInspectionRepository implementation.
/// </summary>
/// <param name="inspections">IInspectionRepository implementation.</param>
public AssetsController(IConfig config, IProfileRepository profiles, IInspectionRepository inspections, ICustomLabelsFactory labels, IValidateRepository validator)
: base()
{
ViewData["_Module"] = "Assets";
_config = config;
_profiles = profiles;
_profiles.ModelState = ModelState;
_inspections = inspections;
_inspections.ModelState = ModelState;
_labels = labels;
_labels.ModelState = ModelState;
_validator = validator;
_validator.CustomLabels = _labels.Assets;
_validator.ModelState = ModelState;
}
App2:命名空间 App1.App2.Controllers
/// <summary>
/// Handles login/logout functionality
/// </summary>
public class AuthController : Controller
{
private ILoginService _login;
private IUtilityRepository _utility;
/// <summary>
/// Creates the Auth controller using the default User Repository which
/// uses the database.
/// </summary>
public AuthController() : this(new LoginService(), new UtilityRepository()) { }
/// <summary>
/// Creates the Auth controller with the given User Repository.
/// </summary>
/// <param name="userRepository">IUserRepository implementation.</param>
public AuthController(ILoginService loginService, IUtilityRepository utility)
: base()
{
ViewData["_Module"] = "Login";
_login = loginService;
_login.ModelState = ModelState;
_utility = utility;
_utility.ModelState = ModelState;
}
我可能会在从哪里开始查看代码的问题上找错树,但我希望有人能在这里看到一些我看不到的明显的东西。或者,也许有人可以告诉我如何以不同的方式执行此操作,因此不涉及共享 Session 对象。在本周的大部分时间里,我一直在断断续续地进行这项工作,因此将不胜感激提供的任何帮助。