0

Hello I would like have some functionality on sesstion expired event, I have created next pipleline for sitecore. after my custom action I need to make redirect to login page. but I got excetion on redirect action.

 public class SessionEnd2
    {
        public  void Process(SessionEndArgs endArgs)
        {
            Assert.ArgumentNotNull(endArgs, "args");
            //do some stuff here
            HttpContext.Current.Response.Redirect("~/login.aspx");
            //WebUtil.Redirect("~/login.aspx", false);

        }
    }

It seems like I can't redirect in this type of piplelines. But I need have way to show user login page. settings in web.config is not works not in None nor Forms mode

 <authentication mode="None">
      <forms  name=".ASPXAUTH" cookieless="UseCookies" loginUrl="~/Login.aspx" timeout="1" slidingExpiration="false" defaultUrl="~/main.aspx"    />
  </authentication>


   в System.Web.HttpResponse.End()
   в System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
   в System.Web.HttpResponse.Redirect(String url)
   в MyLib.SessionEnd2.Process(SessionEndArgs endArgs) в d:\Projects\MyProj\Website\SessionEnd.cs:строка 30
   в (Object , Object[] )
   в Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters)
   в Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   в Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   в Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain)

Thanks for any ideas.

4

2 回答 2

2

会话结束由服务器管理,因此没有与之关联的客户端请求或响应。您看到的错误很可能是由HttpContext.Current.Responsenull 引起的。

sessionEnd您可以考虑挂钩httpRequestBegin并检查每个请求上是否存在 Session 变量,而不是利用管道:

if (Session["Username"] == null)
    // Redirect to login page

或者,您可以通过 JavaScript 定期调用 Web 服务来检查 Session 的状态。这里的好处是您可以警告用户会话即将超时,并提供保持登录状态。

于 2013-06-11T03:54:34.513 回答
0

如果 endArgs 具有 Context 属性,您可能可以执行以下操作:

endArgs.Context.Response.Redirect("~/login.aspx");
于 2013-06-10T22:08:43.937 回答