Files
atakanozbancom/Global.asax.cs
T

49 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace atakanozbancom
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_BeginRequest()
{
var lang = (HttpContext.Current.Request.RequestContext.RouteData.Values["lang"] as string)
?? HttpContext.Current.Request.Cookies["culture"]?.Value
?? "en";
try
{
var ci = CultureInfo.CreateSpecificCulture(lang);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
HttpContext.Current.Response.Cookies.Add(new HttpCookie("culture", ci.Name)
{
Expires = DateTime.Now.AddYears(1),
HttpOnly = true
});
}
catch
{
var fallback = CultureInfo.CreateSpecificCulture("en");
Thread.CurrentThread.CurrentCulture = fallback;
Thread.CurrentThread.CurrentUICulture = fallback;
}
}
}
}