コード例 #1
0
        protected void Session_Start(object sender, EventArgs e)
        {
            // event is raised each time a new session is created
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.ONLINE, 0);

            AppStateHelper.Set(AppStateKeys.ONLINE, currentValue + 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Current.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, this.Request.RawUrl }
            });
        }
コード例 #2
0
        protected void Session_End(object sender, EventArgs e)
        {
            // event is raised when a session is abandoned or expires
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.ONLINE, 0);

            AppStateHelper.Set(AppStateKeys.ONLINE, currentValue - 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Current.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, this.Request.RawUrl }
            });
        }
コード例 #3
0
        public ActionResult Increment()
        {
            int currentValue = (int)AppStateHelper.Get(AppStateKeys.COUNTER, 0);

            AppStateHelper.Set(AppStateKeys.COUNTER, currentValue + 1);
            AppStateHelper.SetMultiple(new Dictionary <AppStateKeys, object> {
                { AppStateKeys.LAST_REQUEST_TIME, HttpContext.Timestamp },
                { AppStateKeys.LAST_REQUEST_URL, Request.RawUrl }
            });
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        /// <summary>
        /// Also we have ability set different type of configuration throughout different bootstraper class (convention => name may be different)
        /// </summary>
        protected void Application_Start()
        {
            //Config WebAPI(2)
            GlobalConfiguration.Configure(WebApiConfig.Register);
            //WebApiConfig.Register(GlobalConfiguration.Configuration);

            //Order is verty important (if i reverse areaRegistration with WebApiConfig => WebAPI 2 attributeRouting won't work
            AreaRegistration.RegisterAllAreas();

            // This method call registers all filters
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            /* Work only with razor View Engine
             * {0} represents the name of the view.
             * {1} represents the name of the controller.
             * {2} represents the name of the area.
             */
            ViewEngines.Engines.Clear();
            /*Avoid searched each view instead in .cshtml files*/
            ViewEngines.Engines.Add(new RazorViewEngine()
            {
                ViewLocationFormats            = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                PartialViewLocationFormats     = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                MasterLocationFormats          = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" },
                AreaViewLocationFormats        = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" },
                AreaMasterLocationFormats      = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" },
                AreaPartialViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" }
            });

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //registration custom binding providers with links to vm
            //ModelBinders.Binders.Add(typeof(SessionStorage), new StorageTableModelBinder());
            //ModelBinders.Binders.Add(typeof(InputMenuViewModel), new InputMenuModelBinder());

            //MVC4 Quick Tip #3–Removing the XML Formatter from ASP.Net Web API
            //GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            //Configure AutoMapper
            AutoMapperBLLConfiguration.Configure();

            //https://github.com/doceandyou/Log4Net
            log4net.Config.XmlConfigurator.Configure(new FileInfo(this.Server.MapPath("~/Web.config")));

            /* Initialize simpleMembership
             * Install-Package Microsoft.AspNet.WebHelpers
             * Install-Package Microsoft.AspNet.WebPages.Data
             * (stop: required dependencies to Microsoft.AspNet.Razor > 3.0 => .Net 4.5
             * WebSecurity.InitializeDatabaseConnection("SecurityConnection", "UserProfile", "UserId", "UserName", true);
             */

            /*Custom value provider (order sense)
             * (First)
             * ValueProviderFactories.Factories.Insert(0,new CustomValueProviderFactory());
             * (End)
             * ValueProviderFactories.Factories.Add(new CustomValueProviderFactory());
             */

            /*Controller Builder
             * ControllerBuilder.Current.DefaultNamespaces.Add("DefaultNamespace");
             */

            //users online
            AppStateHelper.Set(AppStateKeys.ONLINE, 0);
        }