HttpContext.Current是Null访问网站

时间:2015-03-04 08:27:27

标签: httpcontext

我有af网站,我在HttpContext.Current.Application对象中存储了一个全局变量和设置

最近我遇到了一些错误,因为HttpContext.Current返回null,怎么会发生这种情况,我有办法在代码中“重启”应用程序

我从未在调试/测试中得到错误

代码是:

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

0 个答案:

没有答案