public static HandlerMethods GetHandlerMethodsByType(HttpContext context, Type type, string requestPath, bool ignoreCache) { string cacheKey = HandlerMethods.CACHE_PREFIX.ConcatWith(requestPath, type.Namespace, type.Name); HandlerMethods handlerMethods = null; if (!IsDebugging && !ignoreCache) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { handlerMethods = new HandlerMethods(type); if (!IsDebugging && !ignoreCache) { if (requestPath.IsEmpty() || !Directory.Exists(requestPath)) { context.Cache.Insert(cacheKey, handlerMethods); } else { context.Cache.Insert(cacheKey, handlerMethods, new CacheDependency(context.Server.MapPath(requestPath))); } } } return(handlerMethods); }
public static HandlerMethods GetHandlerMethods(HttpContext context, string requestPath) { string path = VirtualPathUtility.ToAbsolute(requestPath); string cacheKey = HandlerMethods.CACHE_PREFIX + path; HandlerMethods handlerMethods = null; if (!IsDebugging) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { Type requestedType = BuildManager.GetCompiledType(path); if (requestedType == null) { requestedType = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)).GetType(); } handlerMethods = new HandlerMethods(requestedType); if (!IsDebugging) { PutToCache(path, context, cacheKey, handlerMethods); } } return(handlerMethods); }
public void ProcessRequest(HttpContext context) { DirectResponse responseObject = new DirectResponse(true); try { HandlerMethods handler = HandlerMethods.GetHandlerMethods(context, context.Request.FilePath); string methodName = HandlerMethods.GetMethodName(context); if (handler == null) { throw new Exception("The Method '{0}' has not been defined.".FormatWith(context.Request.FilePath)); } if (methodName.IsEmpty()) { throw new Exception("No methodName has been set in the configuration."); } DirectMethod directMethod = handler.GetStaticMethod(methodName); if (directMethod == null) { throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(methodName)); } responseObject.Result = directMethod.Invoke(); } catch (Exception e) { if (HandlerMethods.RethrowException(context)) { throw e; } responseObject.Success = false; responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message; } context.Response.Cache.SetNoServerCaching(); context.Response.Cache.SetMaxAge(TimeSpan.Zero); context.Response.Write(responseObject.ToString()); context.Response.End(); }
public static HandlerMethods GetHandlerMethods(HttpContext context, string requestPath) { string path = VirtualPathUtility.ToAbsolute(requestPath); string cacheKey = HandlerMethods.CACHE_PREFIX + path; HandlerMethods handlerMethods = null; if (!IsDebugging) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { try { Type requestedType = BuildManager.GetCompiledType(path); if (requestedType == null) { requestedType = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)).GetType(); } handlerMethods = new HandlerMethods(requestedType); if (!IsDebugging) { PutToCache(path, context, cacheKey, handlerMethods); } } catch (System.Web.HttpException e) { if (!requestPath.EndsWith(".aspx", true, CultureInfo.InvariantCulture)) { return(HandlerMethods.GetHandlerMethods(context, requestPath + "default.aspx")); } throw e; } } return(handlerMethods); }
private void ProcessRequest(HttpApplication app, HttpRequest request) { DirectResponse responseObject = new DirectResponse(true); try { HttpContext context = HttpContext.Current; // Get handler HandlerMethods handler = HandlerMethods.GetHandlerMethods(context, request.FilePath); if (handler == null) { throw new Exception("The Method '{0}' has not been defined.".FormatWith(request.FilePath)); } // Get method name to invoke string methodName = HandlerMethods.GetMethodName(context); if (methodName.IsEmpty()) { throw new Exception("No methodName has been set in the configuration."); } DirectMethod directMethod = handler.GetStaticMethod(methodName); if (directMethod == null) { throw new Exception("The static DirectMethod '{0}' has not been defined.".FormatWith(directMethod)); } object result = directMethod.Invoke(); if (!ResourceManager.AjaxSuccess) { responseObject.Success = false; responseObject.ErrorMessage = ResourceManager.AjaxErrorMessage; } else { responseObject.Result = result; responseObject.Script = ResourceManager.GetInstanceScript(); } } catch (TargetInvocationException e) { if (HandlerMethods.RethrowException(HttpContext.Current)) { throw; } responseObject.Success = false; responseObject.ErrorMessage = IsDebugging ? e.InnerException.ToString() : e.InnerException.Message; } catch (Exception e) { if (HandlerMethods.RethrowException(HttpContext.Current)) { throw; } responseObject.Success = false; responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message; } app.Context.Response.Clear(); app.Context.Response.ClearContent(); app.Context.Response.ClearHeaders(); app.Context.Response.StatusCode = 200; app.Context.Response.ContentType = "application/json"; app.Context.Response.Charset = "utf-8"; app.Context.Response.Cache.SetNoServerCaching(); app.Context.Response.Cache.SetMaxAge(TimeSpan.Zero); app.Context.Response.Write(responseObject.ToString()); app.CompleteRequest(); }
private static void PutToCache(string path, HttpContext context, string cacheKey, HandlerMethods handlerMethods) { BuildDependencySet dependencySet = BuildManager.GetCachedBuildDependencySet(context, path); if (dependencySet != null) { IEnumerable virtualPaths = dependencySet.VirtualPaths; if (virtualPaths != null) { List<string> paths = new List<string>(); foreach (string _path in virtualPaths) { paths.Add(context.Server.MapPath(_path)); } context.Cache.Insert(cacheKey, handlerMethods, new CacheDependency(paths.ToArray())); return; } } context.Cache.Insert(cacheKey, handlerMethods); }
public static HandlerMethods GetHandlerMethodsByType(HttpContext context, Type type, string requestPath, bool ignoreCache) { string cacheKey = HandlerMethods.CACHE_PREFIX.ConcatWith(requestPath, type.Namespace, type.Name); HandlerMethods handlerMethods = null; if (!IsDebugging && !ignoreCache) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { handlerMethods = new HandlerMethods(type); if (!IsDebugging && !ignoreCache) { if (requestPath.IsEmpty() || !Directory.Exists(requestPath)) { context.Cache.Insert(cacheKey, handlerMethods); } else { context.Cache.Insert(cacheKey, handlerMethods, new CacheDependency(context.Server.MapPath(requestPath))); } } } return handlerMethods; }
public static HandlerMethods GetHandlerMethods(HttpContext context, string requestPath) { string path = VirtualPathUtility.ToAbsolute(requestPath); string cacheKey = HandlerMethods.CACHE_PREFIX + path; HandlerMethods handlerMethods = null; if (!IsDebugging) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { try { Type requestedType = BuildManager.GetCompiledType(path); if (requestedType == null) { requestedType = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)).GetType(); } handlerMethods = new HandlerMethods(requestedType); if (!IsDebugging) { PutToCache(path, context, cacheKey, handlerMethods); } } catch (System.Web.HttpException e) { if (!requestPath.EndsWith(".aspx", true, CultureInfo.InvariantCulture)) { return HandlerMethods.GetHandlerMethods(context, requestPath + "default.aspx"); } throw e; } } return handlerMethods; }
private static void PutToCache(string path, HttpContext context, string cacheKey, HandlerMethods handlerMethods) { BuildDependencySet dependencySet = BuildManager.GetCachedBuildDependencySet(context, path); if (dependencySet != null) { IEnumerable virtualPaths = dependencySet.VirtualPaths; if (virtualPaths != null) { List <string> paths = new List <string>(); foreach (string _path in virtualPaths) { paths.Add(context.Server.MapPath(_path)); } context.Cache.Insert(cacheKey, handlerMethods, new CacheDependency(paths.ToArray())); return; } } context.Cache.Insert(cacheKey, handlerMethods); }
public static HandlerMethods GetHandlerMethods(HttpContext context, string requestPath) { string path = VirtualPathUtility.ToAbsolute(requestPath); string cacheKey = HandlerMethods.CACHE_PREFIX + path; HandlerMethods handlerMethods = null; if (!IsDebugging) { handlerMethods = context.Cache[cacheKey] as HandlerMethods; } if (handlerMethods == null) { Type requestedType = BuildManager.GetCompiledType(path); if (requestedType == null) { requestedType = BuildManager.CreateInstanceFromVirtualPath(path, typeof(System.Web.UI.Page)).GetType(); } handlerMethods = new HandlerMethods(requestedType); if (!IsDebugging) { PutToCache(path, context, cacheKey, handlerMethods); } } return handlerMethods; }