使用MVC 2,我如何阻止一个应用程序注销在第二个应用程序中注销用户



在VS2010中,我在同一解决方案中有两个基于MVC 2的web应用程序,它们也共享一个公共的安装项目。一个应用程序是一个配置实用程序,用于在对方应用程序中设置用户和变量。安装后,用户浏览器上的两个IIS目录如下所示:应用程序1:http://localhost/App1/Auth/Login应用程序2:http://localhost/App1/App2/Auth/Login

我遇到的问题是,当用户同时打开两个应用程序,并注销其中一个应用程序时,他们也会注销对方的应用程序。这是一个小问题,但我的任务是纠正它

据我所知,这两个应用程序必须共享同一个Session对象,因为每个控制器中的logout命令方法都会调用Session.Advant().

只有两个控制器能够注销用户;这是那些控制器的构造函数:

App1:命名空间App1.控制器

/// <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;
}

关于从哪里开始查看代码,我可能找错了方向,但我希望有人能在这里看到我看不到的明显内容。或者,也许有人可以告诉我如何以不同的方式执行此操作,这样就不会涉及共享会话对象。在这周的大部分时间里,我一直在断断续续地做这件事,所以如果能提供任何帮助,我们将不胜感激。

您可以将每个应用程序配置为在web.config 中使用不同的会话数据库

编辑:类似的东西

<sessionState mode="SQLServer" sqlConnectionString="Data Source=.SQLEXPRESS;User Id=test;Password=test;Application Name=AppName"  />
    <machineKey
validationKey="SOMEKEY"
validation="SHA1" decryption="AES"
/>

其中somekey对于每个应用程序不同

一个简单、懒惰、避免IIS设置的解决方案是在不同的浏览器中打开每个设置。

最新更新