0

Im having af Website where im storing a global variable with settings in the HttpContext.Current.Application object

Lately i got some errors because the HttpContext.Current returns null, how can that happen and i there some way to "restart" the application in code

I never get the error on debug/test

The code is :

    public static Comito.CMS.Domain.Entity.Solution.Solution GetStoredSolution()
    {
        try
        {
            if (HttpContext.Current.Application["Solution"] == null)
            {
                Comito.CMS.Domain.Entity.Solution.Solution result = Comito.CMS.Helpers.Main.GetStoredSolutionFromConfig();
                if (result != null)
                {
                    HttpContext.Current.Application.Lock();
                    HttpContext.Current.Application["Solution"] = result;
                    HttpContext.Current.Application.UnLock();
                }
                else
                    HttpContext.Current.Response.Redirect("http://www.comito.dk");                            
                return result;
            }
            object tmpSolution = HttpContext.Current.Application["Solution"];
            if (tmpSolution != null)
            {
                if (tmpSolution.GetType() == typeof(Comito.CMS.Domain.Entity.Solution.Solution))
                    return (Comito.CMS.Domain.Entity.Solution.Solution)tmpSolution;
            }
            else
                return Comito.CMS.Helpers.Main.GetStoredSolutionFromConfig();
            return null;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
KeldJ
  • 141
  • 1
  • 10

0 Answers0