谷歌机器人无法获取我的网站 - 给出错误500(ASP.NET MVC)

时间:2014-12-14 12:58:19

标签: c# asp.net .net asp.net-mvc asp.net-mvc-4

我用所有流行的网络浏览器(chrome,ff,IE,Opera)测试了我的网站,一切正常。

在我将我的网站添加到谷歌网站主工具后,我发现谷歌机器人无法获取给出错误500的网站。

详细信息有一个关于 Application_AcquireRequestState 方法的错误,我在globalasax中实现了获取文化信息的方法。当访问者更改网站上的语言时,所有内容都会根据所选语言(文化)进行刷新。我不明白当所有浏览器的开放网站都正确时,谷歌机器人无法获取网站。

完整的错误详情:

  

[NullReferenceException:对象引用未设置为对象的实例。] globaltohum.MvcApplication.Application_AcquireRequestState(Object sender,EventArgs e)+507 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+ 148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+75版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272

这是globalasax中设置文化的方法:

 protected void Application_AcquireRequestState(object sender, EventArgs e)
    {
          bool checkAdmin = false;
         //var lang="tr";
         var cultureInfo= new CultureInfo("tr");
        var handler = Context.Handler as MvcHandler;
        var routeData = handler != null ? handler.RequestContext.RouteData : null;
        if (routeData != null)
        {
            foreach (var item in routeData.Values)
            {
                if (item.Value.ToString() == "AdminEmrah")
                    checkAdmin = true;

            }
        }
         if (!checkAdmin)
         {
        var routeCulture = routeData != null ? routeData.Values["culture"].ToString() : null;
        var languageCookie = HttpContext.Current.Request.Cookies["lang"];
        var userLanguages = HttpContext.Current.Request.UserLanguages;
        var userLanguagesBrowser = Request.UserLanguages;
        CultureInfo ci;
        ci = new CultureInfo(userLanguagesBrowser[0].ToString());
        string stringCi = ci.Name;
        if (stringCi == string.Empty || stringCi == null)
            stringCi = "en";


        if (routeCulture == null && stringCi != null || stringCi != String.Empty && (stringCi.Contains("tr") || stringCi.Contains("en")))
            cultureInfo = new CultureInfo(stringCi);


        cultureInfo = new CultureInfo(
           routeCulture ?? (languageCookie != null
              ? languageCookie.Value
              : userLanguages != null
                  ? userLanguages[0]
                  : "en"));
           }

      if (cultureInfo == null)
            cultureInfo = new CultureInfo("en");

        Thread.CurrentThread.CurrentUICulture = cultureInfo;
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
    }

这是默认路线:

     routes.MapRoute(
          name: "Default",
          url: "{culture}/{controller}/{action}/{id}",
          defaults: new { culture = "tr", controller = "Home", action = "Index", id   =    UrlParameter.Optional }
      );

0 个答案:

没有答案