清除浏览器缓存时如何检查用户会话?

时间:2014-03-11 12:51:55

标签: asp.net-mvc-4 authentication controller server-error

我正在研究ASP.NET MVC4应用程序。

我遇到了用户会话登出的问题。

  
    

问题是,当我清除浏览器的缓存时,我收到服务器错误。

  

以下是Web.Config文件的代码: -

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2000" />
</authentication>

<sessionState mode="InProc" timeout="120" />

我们设置loginUrl。

以下是控制器的代码: -

[CustomAuthorize(Privileges.CategoryCatalog)]
public class ProductController : ProductBaseController
{
      public ProductController ()
      {
        _changedBy = SiteContext.CurrentUser.CurrentUserDto.UsersID;
        _productId = (int)SiteContext.CurrentUser.CurrentUserDto.FKProductID;
      }
 }
  
    

我想在删除浏览器缓存时添加检查控制器以检查用户是否已注销。

  

1 个答案:

答案 0 :(得分:0)

您可以检查会话是否为空或不在控制器端。

喜欢,

if(Session["UserName"] == null)
  // redirect to login page

此会话空白时的代码帮助。