protected void Application_PostAuthenticateRequest() { var httpContext = HttpContext.Current; if (User != null && User.Identity is FormsIdentity && User.Identity.IsAuthenticated) { int userId = GetUserId(); if (userId == 0) { FormsAuthentication.SignOut(); return; } httpContext.User = Thread.CurrentPrincipal = new RoPrincipal(userId, User.Identity); } if (ActionSessionHelper.SessionStateRequired(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath) || DemoMode) { HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); } }
public static void ApiRoute(HttpRouteCollection routes, string url, [AspMvcController] string controller, [AspMvcAction] string action, bool sessionRequired = false) { url = String.Format("{0}/{1}", ConstantStrings.WebApiExecutionPath, url); HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); if (controller != null) { defaults["controller"] = controller; } if (action != null) { defaults["action"] = action; } IHttpRoute route = routes.CreateRoute(url, defaults, new Dictionary <string, object>()); routes.Add(route.RouteTemplate, route); if (sessionRequired) { // в урле передаётся название параметра. превращаем его в регулярку. var urlRegex = $"^~/" + Regex.Replace(url, @"{.+?}", "(.+?)"); ActionSessionHelper.RegisterUrlRegex(urlRegex); } }
private void InitSessionUrls() { ActionSessionHelper.RegisterUrlRegex("/api/"); }