MVC 2を使用すると、1つのアプリログアウトが2番目のアプリでユーザーのログアウトを停止するにはどうすればよいですか?
-
25-10-2019 - |
質問
VS2010では、共通のセットアッププロジェクトも共有するのと同じソリューション内に2つのMVC 2ベースのWebアプリがあります。 1つのアプリは、対立するアプリでユーザーと変数を設定するための構成ユーティリティです。インストールすると、2つのIISディレクトリがユーザーのブラウザでこのように見えます:App1: http:// localhost/app1/auth/loginApp2: http:// localhost/app1/app2/auth/login
私が抱えている問題は、ユーザーが両方のアプリを同時に開いていて、そのうちの1つからログアウトしている場合、反対側のアプリからログアウトされます。これは小さな問題ですが、私はそれを修正することを任されています。
私が知ることができることから、各コントローラーのログアウトコマンドメソッドがsession.abnand()を呼び出すため、2つのアプリが同じセッションオブジェクトを共有している必要があります。
ユーザーをログアウトする機能があるのは2つのコントローラーのみです。これがそれらのコントローラーのコンストラクターのものです。
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;
}
私はコードをどこで見始めるかについて間違った木をbarえているかもしれませんが、私は誰かが私ができないことが明白な何かを見ることができることを望んでいます。または、誰かがこれを違った方法で行う方法を教えてくれるので、共有セッションオブジェクトが関係していません。私は今週の大半をオンとオフに取り組んできたので、提供される支援は大歓迎です。
解決
web.configで別のセッションデータベースを使用するように各アプリケーションを構成できます
編集:何か
<sessionState mode="SQLServer" sqlConnectionString="Data Source=.\SQLEXPRESS;User Id=test;Password=test;Application Name=AppName" />
<machineKey
validationKey="SOMEKEY"
validation="SHA1" decryption="AES"
/>
一部のキーがアプリケーションごとに異なる場合
他のヒント
シンプルで怠zyなIIS設定を回避するソリューションは、それぞれを異なるブラウザで開くことです。