1

I add custom error exception in Global.asax. It works on debug mode but when I publish it in IIS 7.0 it does not work: Global.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;
    }

In 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);
        }
    }

When I run website in debug Mode via Visual Studio 2010 it is work but it does not redirect to ExceptionHandler.asax in Publish Mode

1 Answers1

0

This is because global.asax file is not published. Manually copy that file into your published folder.

If this is a web application project then you can set global.asax file property to be content. Unfortunately if it is website then you have to manually do it.

I am still breaking my head how to include global.asax into publish list. No answer yet.

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

Community
  • 1
  • 1
Esen
  • 973
  • 1
  • 21
  • 47