使用MVC 2,如何停止一个应用程序注销,以在第二个应用程序中记录用户?
-
25-10-2019 - |
题
在VS2010中,我在同一解决方案中有两个基于MVC 2的Web应用程序,它们也共享一个共同的设置项目。一个应用程序是用于在对方应用中设置用户和变量的配置实用程序。安装后,两个IIS目录在用户的浏览器上看起来像这样:app1: http:// localhost/app1/auth/loginapp2: http:// localhost/app1/app2/auth/login
我遇到的问题是,当用户同时打开两个应用程序时,并且在其中一个应用程序中登录了其中的一个应用程序时,他们也已将其记录在相对的应用程序中。这是一个小问题,但是我一直在纠正它。
据我所知,这两个应用程序必须共享同一会话对象,因为每个控制器中的注销命令方法调用session.abandon()。
只有两个控制器能够注销用户。这是这些控制器的构造函数:
app1:namespace 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:namespace 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"
/>
每个应用程序都有不同的地方
其他提示
一个简单,懒惰的IIS设置避免解决方案是在其他浏览器中打开每个解决方案。
不隶属于 StackOverflow