using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Routing; using Yavsc.Formatters; using Yavsc.Model.FrontOffice; using System.Web.SessionState; using System.Web.Mvc; using System.Web.Http; using System.Web.WebPages.Scope; using System.Reflection; using System.Web.Configuration; namespace Yavsc { /// /// Mvc application. /// public class MvcApplication : System.Web.HttpApplication { /// /// Registers the routes. /// /// Routes. public static void RegisterRoutes (RouteCollection routes) { // Should be FrontOffice in a POS, string defaultController = WebConfigurationManager.AppSettings ["DefaultController"]; if (defaultController == null) defaultController = "Home"; routes.IgnoreRoute ("{resource}.axd/{*pathInfo}"); // not used routes.IgnoreRoute ("Scripts/{*pathInfo}"); // web user side scripts routes.IgnoreRoute ("App_Theme/{*pathInfo}"); // sites themes routes.IgnoreRoute ("images/{*pathInfo}"); // site images routes.IgnoreRoute ("users/{*pathInfo}"); // user's files routes.IgnoreRoute ("avatars/{*pathInfo}"); // user's avatar routes.IgnoreRoute ("bfiles/{*pathInfo}"); // Blog files routes.IgnoreRoute ("xmldoc/{*pathInfo}"); // xml doc routes.IgnoreRoute ("htmldoc/{*pathInfo}"); // html doc routes.IgnoreRoute ("fonts/{*pathInfo}"); // fonts routes.IgnoreRoute ("favicon.ico"); // favorite icon routes.IgnoreRoute ("favicon.png"); // favorite icon routes.IgnoreRoute ("robots.txt"); // for search engine robots routes.MapRoute ( "View", "v/{title}", new { controller = "Blogs", action = "Index", title=UrlParameter.Optional } ); routes.MapRoute ( "Blogs", "b/{user}/{title}", new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title=UrlParameter.Optional } ); /* routes.MapRoute ( "Artistes", "a/{artiste}", new { controller = "Artistes", action = "Index", artiste = UrlParameter.Optional } ); */ routes.MapRoute ( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } /// /// Starts the Application. /// protected void Application_Start () { AreaRegistration.RegisterAllAreas (); WebApiConfig.Register (GlobalConfiguration.Configuration); RegisterRoutes (RouteTable.Routes); } /// /// Applications the post authorize request. /// protected void Application_PostAuthorizeRequest() { if (IsWebApiRequest()) { HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); } } private bool IsWebApiRequest() { return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative); } /// /// begins a request against this application. /// protected void Application_BeginRequest() { var ob = typeof( AspNetRequestScopeStorageProvider).Assembly.GetType( "System.Web.WebPages.WebPageHttpModule").GetProperty ("AppStartExecuteCompleted", BindingFlags.NonPublic | BindingFlags.Static); ob.SetValue(null, true, null); } } }