Hi I have been working with the International version of the : ASP.NET MVC 3 Internationalization - Part 2 (NerdDinner) at: http://afana.me/post/aspnet-mvc-internationalization-part-2.aspx
Unfortunately this contains one major bug. The thing is I have downloaded the code/project and made a build and published it to a local folder (there are some minor bugs that needs to be fixed in order to make a publish) and then uploaded the files to my webhotel. The homepage was seemingly working ok, but then I looked into Google Web Master Tool and made a crawling on the site and found out that not a single page in the site can be index, even the root node cannot be fetched by googles crawler:
This is the error I got when try to fetch the root (www.thehomepage.com) or any pages in the site:
Page is unreachable
HTTP/1.1 500 Internal Server Error
[NullReferenceException: Object reference not set to an instance of an object.]
NerdDinner.Controllers.BaseController.ExecuteCore() +164
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
//I have below copy/paste some code from the project which I think may be relevant:
public class BaseController : Controller
{
protected override void ExecuteCore()
{
string cultureName = null;
// Attempt to read the culture cookie from Request
HttpCookie cultureCookie = Request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else
cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
// Validate culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
// Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
base.ExecuteCore();
}
}
//And from the global.asax, this may be relevant
void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
string encTicket = authCookie.Value;
if (!String.IsNullOrEmpty(encTicket))
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encTicket);
NerdIdentity id = new NerdIdentity(ticket);
GenericPrincipal prin = new GenericPrincipal(id, null);
HttpContext.Current.User = prin;
}
}
}
void MvcApplication_AuthenticateRequest(object sender, EventArgs e)
{
}
/* NerdDinner i18n Custom caching */
public override string GetVaryByCustomString(HttpContext context, string arg)
{
// It seems this executes multiple times and early, so we need to extract language again from cookie.
if (arg == "culture") // culture name (e.g. "en-US") is what should vary caching
{
string cultureName = null;
// Attempt to read the culture cookie from Request
HttpCookie cultureCookie = Request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else
cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
// Validate culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
return cultureName.ToLower();// use culture name as cache key, "es", "en-us", "es-cl", etc.
}
return base.GetVaryByCustomString(context, arg);
}
}
Hope someone can take a look and tell what is rejecting google crawler so that i cannot fetch anything.
The Request.UserLangauges
object is based upon using the request coming from a browser. The googlebot's crawler isn't a browser, therefor you should test first if the Request.UserLangauges
isn't null, something like this:
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else {
if (Request.UserLanguages != null && Request.UserLanguages.Length > 0)
cultureName = Request.UserLanguages[0];
else
cultureName = "the culture you'd like to use";
}