コード例 #1
0
        public HttpResponseMessage SaveRedirect(MappingModel model)
        {
            var map = new Mapping();

            map.SourceUrl = model.SourceUrl.Trim();
            if (!string.IsNullOrEmpty(model.TargetUrl))
            {
                map.TargetUrl = model.TargetUrl;
            }
            else if (model.TargetTabId > 0)
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = DotNetNuke.Common.Globals.NavigateURL(map.TargetTabId, PortalSettings, "");
            }
            else
            {
                // keep giving 404
                map.EnableLogging = false;
            }
            if (map != null)
            {
                map.UseRegex = false;
                var cfg = RedirectConfig.Instance;
                cfg.Mappings.Add(map);
                cfg.ToFile(Common.RedirectConfigFile());
                RedirectConfig.Reload(PortalSettings.PortalId);
            }

            // set handledon/handledby in table
            RedirectController.SetHandledUrl(model.SourceUrl);

            return(Request.CreateResponse(HttpStatusCode.OK, new {}));
        }
コード例 #2
0
        public HttpResponseMessage SaveMapping(MappingModel model) // string id, bool useRegex, string sourceUrl, string targetUrl, int targetTabId)
        {
            var map = RedirectConfig.Instance.Mappings.FirstOrDefault(m => m.Id == model.Id);

            if (!string.IsNullOrEmpty(model.Id) && map == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (map == null && string.IsNullOrEmpty(model.Id))
            {
                map    = new Mapping();
                map.Id = Guid.NewGuid().ToString();
                RedirectConfig.Instance.Mappings.Add(map);
            }

            map.StatusCode    = model.StatusCode;
            map.SourceUrl     = model.SourceUrl.Trim();
            map.UseRegex      = model.UseRegex;
            map.EnableLogging = model.EnableLogging;
            if (!string.IsNullOrEmpty(model.TargetUrl))
            {
                map.TargetTabId = Null.NullInteger;
                map.TargetUrl   = model.TargetUrl;
            }
            else if (model.TargetTabId > 0)
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = DotNetNuke.Common.Globals.NavigateURL(map.TargetTabId, PortalSettings, "");
            }
            else if (model.TargetTabId == -1) // matches with number in js file
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = "";
            }
            else if (model.TargetTabId == -2) // matches with number in js file, meaning it needs to be deleted
            {
                // remove mapping
                RedirectConfig.Instance.Mappings.Remove(map);
                map = null;
            }

            RedirectConfig.Instance.ToFile(Common.RedirectConfigFile());
            RedirectConfig.Reload(PortalSettings.PortalId);

            // set handledon/handledby in table
            if (!model.UseRegex)
            {
                RedirectController.SetHandledUrl(model.SourceUrl);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, map == null ? null : new MappingModel(map)));
        }