public void Init(ServiceLocator sl, ref PluginSetting setting) { if (!setting.Enable) { return; } IUrlMappingProvider urlMapping = sl.Resolve <IUrlMappingProvider>(); UrlMappingItem item = UrlMapping.Utility.CreateTemplatedMappingItem("_res.aspx"); item.Id = "_res_"; item.Action = "proc"; item.Index = -1; item.SubIndex = -1; item.SubsubIndex = -1; urlMapping.AddMapping(item); item = UrlMapping.Utility.CreateTemplatedMappingItem("[]_resc.aspx"); item.Id = "_resc_"; item.Action = "proc"; item.Index = -1; item.SubIndex = -1; item.SubsubIndex = -1; urlMapping.AddMapping(item); }
public void AddMapping(string siteKey, UrlMappingItem item) { UrlMappingItemCollection coll; if (_manualItems.ContainsKey(siteKey)) { coll = _manualItems[siteKey]; } else { coll = new UrlMappingItemCollection(); _manualItems[siteKey] = coll; } coll.Merge(item); }
void findRoutes(string siteKey, Dictionary <string, Type> types) { UrlMappingConfig config = UrlMappingConfig.Instance; IUrlMappingProvider provider = ServiceLocator.Instance.Resolve <IUrlMappingProvider>(); foreach (var controller in types) { foreach (MethodInfo m in controller.Value.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance)) { object[] objs = m.GetCustomAttributes(typeof(UrlRouteAttribute), true); if (objs.Length == 0) { continue; } UrlRouteAttribute attr = objs[0] as UrlRouteAttribute; UrlMappingItem item = UrlMapping.Utility.CreateTemplatedMappingItem(string.Empty, attr.Template, UrlMapping.Utility.GetHref(attr.Href), config.IncomingQueryStringBehavior); item.UrlTemplate = attr.Template; item.Index = -1; item.SubIndex = -1; item.SubsubIndex = -1; item.Title = attr.Title; item.Id = controller.Key; item.Action = m.Name; provider.AddMapping(siteKey, item); } } }
public void AddMapping(UrlMappingItem item) { _manualGlobalRoutes.Merge(item); }
/// <summary> /// Creates a <see cref="UrlMappingItem" /> given a name, templated URL string, and redirection string. /// </summary> /// <param name="name">A name for this mapping item</param> /// <param name="templatedUrl">A template for URLs to be matched</param> /// <param name="redirection">The redirection that the UrlMappingModule should apply when incoming URLs match the template.</param> /// <param name="qsBehavior">defines how the UrlMappingModule should treat querystring values on an incoming URL for pattern matching; this is typically provided through declarative configuration</param> /// <returns>The created <see cref="UrlMappingItem" /></returns> /// <remarks> /// <para> /// The template URL string is relative to the web application and may or may not include /// the "~/" characters at the beginning. The template may indicate an exact URL to match, /// for example <i>Reports/Summary.aspx</i> or may include token names surrounded /// by [SquareBrackets] for dynamic matching, such as <i>Reports/[ID]/[Action].aspx</i>. /// When dynamic templates are matched in runtime by the UrlMappingModule, dynamic tokens /// are appended to the redirection string as querystring items, /// such as <i>?ID=<i>xxx</i>&Action=<i>xxx</i></i>. /// </para> /// <para> /// The redirection string may be an absolute URL, such as <i>http://www.microsoft.com</i>, /// a server-relative URL beginning with a "/", such as <i>/AnotherAppOnThisServer/page.aspx</i>, /// or an application-relative URL to a concrete resource, optionally beginning with a "~/", such as /// <i>~/ReportSummary.aspx</i> or <i>ReportSummary.aspx</i>. /// </para> /// </remarks> public static UrlMappingItem CreateTemplatedMappingItem(string name, string templatedUrl, string redirection, IncomingQueryStringBehavior qsBehavior) { UrlMappingItem item = new UrlMappingItem(name, CreateTemplatedMappingRegex(templatedUrl, qsBehavior), redirection); item.UrlTemplate = templatedUrl; return item; }
void proc() { JContext jc = JContext.Current; HttpContext context = jc.Context; // set a ajax request token jc.IsAjaxRequest = true; // get querystring string qs = context.Request.Params["querystring"]; if (StringUtil.HasText(qs)) { qs = qs.TrimStart('?'); jc.QueryString.Add(StringUtil.DelimitedEquation2NVCollection("&", qs)); } if (context.Request.UrlReferrer != null) { UrlMappingModule module = UrlMappingModule.Instance; if (module != null) { UrlMappingItem mapping = null; jc.QueryString.Add(module.GetMappedQueryString(context.Request.UrlReferrer.AbsolutePath, out mapping)); if (mapping != null) { NavigationInfo navi = new NavigationInfo(); navi.Set(mapping, UrlMappingModule.GetUrlRequested(context.Request.UrlReferrer.AbsolutePath)); jc.Navigation = navi; // fire url matched event module.OnUrlMatched(); } } } // set view data UrlMappingModule.SetViewData(); string classId = context.Request.Params[CLASS_ID_PARAM]; string methodName = context.Request.Params[METHOD_NAME_PARAM]; string methodJsonArgs = context.Request.Params[METHOD_ARGS_PARAM]; string jsonp = context.Request.Params[JSONP]; object result; int cacheMinutes = -1; if (string.IsNullOrEmpty(classId) || string.IsNullOrEmpty(methodName)) { result = "null"; } else { AjaxConfiguration config = AjaxConfiguration.GetConfig(); AjaxMethod m = null; try { string id = jc.Navigation.Id; if (id.Contains(":")) { id = id.Substring(id.IndexOf(":") + 1); } AjaxClass c = config.FindClass(classId, id); m = config.FindMethod(c, methodName); if (string.Equals("Post", m.AjaxType, StringComparison.InvariantCultureIgnoreCase)) { cacheMinutes = -1; } else if (StringUtil.HasText(m.CacheTest)) { cacheMinutes = methodJsonArgs.Equals(m.CacheTest) ? cacheMinutes : -1; } // before execute BeforeExecuteEventArgs e = new BeforeExecuteEventArgs() { JContext = jc, TypeName = c.Key, MethodName = m.MethodName }; OnBeforeExecute(e); if (e.PreventDefault) { result = e.ReturnValue; goto response; } if (c.Type != null) { result = m.Invoke(c.Type, methodJsonArgs); } else { result = m.Invoke(c.TypeString, methodJsonArgs); } } catch (Exception ex) { LogManager.GetLogger <AjaxController>().Error("ajax handler error." + ExceptionUtil.WriteException(ex)); AjaxServerException ajaxEx = null; if (m != null) { ajaxEx = m.Exception; } if (ajaxEx != null) { result = ajaxEx.ToJson(); } else { result = null; } } } goto response; response: OnAfterExecute(result); ResponseUtil.OutputJson(context.Response, result, cacheMinutes, jsonp); ContentType = context.Response.ContentType; }
public void AddMapping(string siteKey, UrlMappingItem item) { UrlMappingItemCollection coll; if (_manualItems.ContainsKey(siteKey)) coll = _manualItems[siteKey]; else { coll = new UrlMappingItemCollection(); _manualItems[siteKey] = coll; } coll.Merge(item); }
public NameValueCollection GetMappedQueryString(string urlRequested, out UrlMappingItem mapping) { mapping = null; urlRequested = (_qsBehavior == IncomingQueryStringBehavior.Include ? new Url(urlRequested).PathAndQuery : new Url(urlRequested).Path); urlRequested = GetUrlRequested(urlRequested); // first check out from cache Dictionary<string, UrlMappingItem> sitecaches = _site_caches; if (sitecaches.ContainsKey(urlRequested)) mapping = sitecaches[urlRequested]; if (mapping == null) { foreach (UrlMappingItem item in _provider.UrlMappings ?? new UrlMappingItemCollection()) { Match match = item.UrlTarget.Match(urlRequested); if (match.Success) { // do we want to add querystring parameters for dynamic mappings? NameValueCollection qs = new NameValueCollection(); if (match.Groups.Count > 1) { for (int i = 1; i < match.Groups.Count; i++) qs.Add(item.UrlTarget.GroupNameFromNumber(i), match.Groups[i].Value); } mapping = item; if (!item.UrlTemplate.Contains("[")) sitecaches[urlRequested] = item; return qs; } } } return new NameValueCollection(); }
public void AddMapping(string siteKey, UrlMappingItem item) { _manualAdded.Add(item); _coll.Merge(item); }
public void AddMapping(UrlMappingItem item) { AddMapping(AreaConfig.Instance.AreaKey, item); }