風になびいているので、ここで質問しようと思ったのですが... これが明らかで、以前に回答されたことがあれば教えてください。
ページをクリックして1人のユーザーで実行しているときに正常に動作するMVC 3サイトを構築しています。ただし、更新を狂ったように押すと、最終的に「セッションが閉じられました」とヒットします。
一番下にたどり着くために、ほとんどすべてのリポジトリを分離したので、ホームページでエラーが発生していることがわかります。リポジトリで呼び出されるのは、データベース テーブルからユーザーの名前を取得することだけです。
データベースとして Postgres を使用し、NauckIT の ASP.NET メンバーシップ プロバイダーを使用しています。メイン データベースも Postgres (ただし、別のデータベース) です。
セッション管理は、次のコードを使用して行われます。
public class MvcApplication : System.Web.HttpApplication
{
public static ISessionFactory SessionFactory =
NHibernateHelper.GetSessionFactory();
public MvcApplication()
{
this.BeginRequest += MvcApplication_BeginRequest;
this.EndRequest += MvcApplication_EndRequest;
}
void MvcApplication_BeginRequest(object sender, EventArgs e)
{
CurrentSessionContext.Bind(SessionFactory.OpenSession());
}
void MvcApplication_EndRequest(object sender, EventArgs e)
{
CurrentSessionContext.Unbind(SessionFactory).Dispose();
}
}
ログイン情報を取得するコードは次のとおりです。
public Login GetCurrentLogin()
{
return Session.Query<Login>().FirstOrDefault(l => l.UserID == UserAccessRepository.UserID);
}
は、フォーム認証 Cookie から をUserAccessRepository
取得するだけです。userid
セッションは、次を使用してリポジトリに挿入されます。
ninjectKernel.Bind<IUserRepository>().To<NHUserRepository>();
ninjectKernel.Bind<ILeagueRepository>().To<NHLeagueRepository>().InThreadScope();
ninjectKernel.Bind<ISession>()
.ToMethod(m => MvcApplication.SessionFactory.GetCurrentSession())
sessionfactory は次のものに由来します。
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
public static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{ var rawConfig = new Configuration();
rawConfig.SetNamingStrategy(new PostgresNamingStrategy());
var configuration = Fluently.Configure(rawConfig)
.Database(PostgreSQLConfiguration.Standard.ConnectionString(ConnectionString).ShowSql().Dialect("NHibernate.Dialect.PostgreSQL82Dialect"))
.Mappings(m =>
m.AutoMappings.Add(AutoMap.AssemblyOf<Event>(new AutoMapConfiguration())
)).ExposeConfiguration(cfg =>
cfg.SetProperty("current_session_context_class", "web")
_sessionFactory = configuration.BuildSessionFactory();
Debug.WriteLine("Built SessionFactory");
}
return _sessionFactory;
明確にするために、クリックしてページを移動する標準的なインスタンスでは問題なく動作しますが、狂ったように F5 キーを押すと、セッションが閉じられるという問題が発生します。
更新:関連性があるかどうかはわかりませんが、メソッドBaseController
内でこれを確認している主な場所です。OnActionExecuting
上記の方法で解決したようです。