2

I have a custom attribute class which inherits from AuthorizeAttribute. Sometimes the parameter httpContext.Session is null. How is this possible? The Session supposed to be alive as long as I am logged/active, right? I am not brwosing for 20 minutes or longer, in fact I am just browsing for 0-2 minutes and sometimes the Session property is null.

We have this bug since we are switched from MVC 2 (.NET 3.5) to MVC 4.5 (.Net 4.5) Is it possible that this is the cause of the problems?

How can I solve this?

4

2 に答える 2

1

これはどのように可能ですか?

これは、セッション状態を無効にしている場合に発生する可能性があります。セッション状態を無効にするには、web.config に以下を含めることができます。

<sessionState mode="Off" />

または、コントローラー/ベースコントローラー/アクションを次の[SessionState]属性で装飾することもできます。

[SessionState(SessionStateBehavior.Disabled)]
public class HomeController : Controller
{
    ...
}
于 2012-10-08T13:41:02.937 に答える