【问题标题】:Redirect Does not work in Global.asax publish time重定向在 Global.asax 发布时间不起作用
【发布时间】:2012-12-02 08:21:12
【问题描述】:

我在 Global.asax 中添加了自定义错误异常。它在调试模式下工作,但是当我在 IIS 7.0 中发布它时它不起作用: 全球.asax:

  void Application_Error(object sender, EventArgs e)
    {
    // Code that runs when an unhandled error occurs
        //Ramezani V4.5: Change0002 29-08-91        
        if (Context.AllErrors[0].InnerException != null)
        {
            try
            {
                bool IsValid = (Session["ExceptionHandler"] == null);
                ArisFramWork.ExceptionHandler handler = new ArisFramWork.ExceptionHandler(Request.AppRelativeCurrentExecutionFilePath, (Context.AllErrors[0] == null ? new Exception("No Error Found") : Context.AllErrors[0]));
                Session["ExceptionHandler"] = handler;
                string redirectURL = (IsValid ? Request.AppRelativeCurrentExecutionFilePath : "~/ExceptionHandler.aspx");
                Response.Redirect((Request.QueryString.Count == 0 ? redirectURL : redirectURL + "?" + Request.QueryString.ToString()));    
            }
            catch
            {
                Session["ExceptionHandler"] = null;
            }
        }
        else
        {
            Response.Redirect("~/FileAccess.aspx");
        }
    }
 void Application_Start(object sender, EventArgs e)
    {
        FastReport.Utils.Config.WebMode = true;
        // Code that runs on application startup
        //Ramezani V4.5: Change0002 29-08-91       
        //if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)       
            Session["ExceptionHandler"] = null;
    }

在 ExceptionHandler.aspx 中:

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            publicclass.MessageBox("Hello ExceptionHandler", this);
            if (Session["ExceptionHandler"] != null)
            {
                if(ExceptionHandlerBulletedList.Items.Count==1)
                    ExceptionHandlerBulletedList.Items.RemoveAt(0);
                List<ArisFramWork.ExceptionHandler> ExecutionCollection = (List<ArisFramWork.ExceptionHandler>)Session["ExceptionHandler"];
                if (ExecutionCollection.Count < 1)
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "CloseForm", "window.close();", true);
                    return;
                }       
                .....
                Session["ExceptionHandler"] = null;
            }
        }
        catch (Exception exception)
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "CloseForm", "window.close();", true);
        }
    }

当我通过 Visual Studio 2010 在调试模式下运行网站时,它可以工作,但它不会在发布模式下重定向到 ExceptionHandler.asax

【问题讨论】:

  • 还有答案!我无法解决这个问题。当我使用 IIS 5.0 时,IE 6.0 就可以了!!!!!!

标签: redirect iis-7.5 publish global-asax


【解决方案1】:

这是因为 global.asax 文件没有发布。手动将该文件复制到您发布的文件夹中。

如果这是一个 Web 应用程序项目,那么您可以将 global.asax 文件属性设置为内容。不幸的是,如果它是网站,那么您必须手动进行。

我仍然不知道如何将 global.asax 包含到发布列表中。还没有答案。

global.asax works on local computer but not after i publish to server

【讨论】:

  • 确保您的网站下有 PrecompiledApp.config 文件。
猜你喜欢
  • 2013-01-15
  • 1970-01-01
  • 2019-02-24
  • 1970-01-01
  • 2013-03-24
  • 2020-07-15
  • 1970-01-01
  • 2013-11-26
  • 2016-01-10
相关资源
最近更新 更多