2

我正在尝试进行重定向,我有一个单例类,它是我的配置类,获取有关此的信息并使用我的连接字符串,我将这些数据保存在加密文件中,我正在使用每个请求的会话,然后在安装之前我需要检查会话配置文件,如果没有我抛出异常。

 protected void Application_BeginRequest()
 {
    if (!Settings.Data.Valid())
       throw new SingletonException();

     var session = SessionManager.SessionFactory.OpenSession();
     if (!session.Transaction.IsActive)
        session.BeginTransaction(IsolationLevel.ReadCommitted);

     CurrentSessionContext.Bind(session);
 }

如果有,我必须重定向到作为单例类的设置页面。

protected void Application_Error(Object sender, EventArgs e)
{
    Exception exc = Server.GetLastError();
    while (exc != null)
    {
        if (exc.GetType() == typeof(SingletonException))
        {
            Response.Redirect(@"~/Settings/Index");
        }

        exc = exc.InnerException;
    }
}

但是我遇到了这个重定向的问题,浏览器中的链接正在改变,但我有一个重定向循环,已经尝试清除 cookie 并启用外部站点的选项。 在此处输入图像描述 有人能帮我吗?

4

2 回答 2

2

问题是你正在使用while循环所以它是无限循环 if excis not null,你必须在if这里使用条件:

if(exc != null)
{
  if (exc.GetType() == typeof(SingletonException))
  {
      Response.Redirect(@"~/Settings/Index");
  }

  exc = exc.InnerException;
}
于 2015-04-16T12:32:52.357 回答
1

只需将 Application_BeginRequest 设置为无效时什么都不做。

 protected void Application_BeginRequest()
        {
            if (!Settings.Data.Valid())
                return;

            var session = SessionManager.SessionFactory.OpenSession();
            if (!session.Transaction.IsActive)
                session.BeginTransaction(IsolationLevel.ReadCommitted);
            CurrentSessionContext.Bind(session);
        }
于 2015-04-20T16:52:12.210 回答