2014-10-10 23:57:02 +01:00
|
|
|
|
using System;
|
2016-08-21 15:17:56 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2015-05-30 15:14:09 +01:00
|
|
|
|
using System.Web;
|
2014-10-10 23:57:02 +01:00
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Routing;
|
2017-04-12 15:04:23 +01:00
|
|
|
|
using System.Web.Security;
|
2016-08-30 11:39:52 +01:00
|
|
|
|
using BuildFeed.Code;
|
2016-08-21 15:17:56 +01:00
|
|
|
|
using BuildFeed.Code.Options;
|
2016-08-19 22:10:55 +01:00
|
|
|
|
using BuildFeed.Model;
|
2014-10-10 23:57:02 +01:00
|
|
|
|
|
|
|
|
|
namespace BuildFeed
|
|
|
|
|
{
|
2017-02-23 20:53:49 +00:00
|
|
|
|
public class MvcApplication : HttpApplication
|
|
|
|
|
{
|
|
|
|
|
protected void Application_Start()
|
|
|
|
|
{
|
|
|
|
|
// Disable ASP.NET MVC version header
|
|
|
|
|
MvcHandler.DisableMvcResponseHeader = true;
|
|
|
|
|
|
|
|
|
|
// Don't bother looking for the legacy aspx view engine.
|
|
|
|
|
ViewEngines.Engines.Clear();
|
|
|
|
|
ViewEngines.Engines.Add(new RazorViewEngine());
|
|
|
|
|
|
2017-05-20 23:58:04 +01:00
|
|
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
2017-02-23 20:53:49 +00:00
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
|
|
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
|
|
|
|
|
2018-02-06 22:16:37 +00:00
|
|
|
|
var db = new DateTimeModelBinder();
|
2017-02-23 20:53:49 +00:00
|
|
|
|
|
|
|
|
|
ModelBinders.Binders.Add(typeof(DateTime), db);
|
|
|
|
|
ModelBinders.Binders.Add(typeof(DateTime?), db);
|
|
|
|
|
|
2017-05-25 21:21:40 +01:00
|
|
|
|
ModelMappings.Initialise();
|
|
|
|
|
|
2017-04-12 15:04:23 +01:00
|
|
|
|
Roles.CreateRole("Administrators");
|
|
|
|
|
Roles.CreateRole("Editors");
|
|
|
|
|
Roles.CreateRole("Users");
|
|
|
|
|
|
2017-02-23 20:53:49 +00:00
|
|
|
|
MongoConfig.SetupIndexes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetVaryByCustomString(HttpContext context, string custom)
|
|
|
|
|
{
|
2018-02-06 22:16:37 +00:00
|
|
|
|
var parts = custom.Split(';');
|
2017-02-23 20:53:49 +00:00
|
|
|
|
var varyParts = new List<string>();
|
2018-02-06 22:16:37 +00:00
|
|
|
|
var contextWrapper = new HttpContextWrapper(context);
|
2017-02-23 20:53:49 +00:00
|
|
|
|
|
|
|
|
|
foreach (string part in parts)
|
2016-08-21 15:17:56 +01:00
|
|
|
|
{
|
2017-02-23 20:53:49 +00:00
|
|
|
|
switch (part)
|
|
|
|
|
{
|
|
|
|
|
case "userName":
|
|
|
|
|
varyParts.Add($"user:{context.User.Identity.Name}");
|
|
|
|
|
break;
|
|
|
|
|
case "lang":
|
2017-06-20 21:44:19 +01:00
|
|
|
|
varyParts.Add($"lang:{Locale.DetectCulture(contextWrapper).IetfLanguageTag}");
|
2017-02-23 20:53:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case "theme":
|
|
|
|
|
varyParts.Add($"theme:{Theme.DetectTheme(contextWrapper)}");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-21 15:17:56 +01:00
|
|
|
|
}
|
2015-05-30 15:14:09 +01:00
|
|
|
|
|
2017-02-23 20:53:49 +00:00
|
|
|
|
return string.Join(";", varyParts.OrderBy(s => s));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-13 12:35:21 +01:00
|
|
|
|
}
|