Ejemplo n.º 1
0
        static OtherResult HttpAddRedirect(HttpContext context, DomainSetting domain)
        {
            var address      = context.GetQueryTextParameter("Address");
            var target       = context.GetQueryTextParameter("Target");
            var permanent    = context.GetQueryBooleanParameter("Permanent");
            var queryProcess = context.GetQueryBooleanParameter("QueryProcess");

            var redirect = RedirectTarget.Create(target, permanent, queryProcess);

            if (domain.Redirects.TryAdd(address, redirect))
            {
                SettingHost.SaveSetting();
                return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect)));
            }
            else
            {
                return(new Status409Result());
            }
        }
Ejemplo n.º 2
0
        static OtherResult HttpUpdateRedirect(HttpContext context, DomainSetting domain)
        {
            var address      = context.GetQueryTextParameter("Address");
            var newAddress   = context.GetQueryOptionalTextParameter("NewAddress");
            var target       = context.GetQueryTextParameter("Target");
            var permanent    = context.GetQueryBooleanParameter("Permanent");
            var queryProcess = context.GetQueryBooleanParameter("QueryProcess");

            if (newAddress != null && newAddress != address)
            {
                //Change domain name
                if (domain.Redirects.ContainsKey(newAddress))
                {
                    return(new Status409Result());
                }
                else if (domain.Redirects.Remove(address))
                {
                    var redirect = RedirectTarget.Create(target, permanent, queryProcess);
                    domain.Redirects.Add(newAddress, redirect);
                    SettingHost.SaveSetting();
                    return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect)));
                }
                else
                {
                    return(new Status410Result());
                }
            }
            else if (domain.Redirects.TryGetValue(address, out RedirectTarget redirect))
            {
                redirect.Update(target, permanent, queryProcess);
                SettingHost.SaveSetting();
                return(new Status200Result <RedirectTargetWithAddress>(new RedirectTargetWithAddress(address, redirect)));
            }
            else
            {
                return(new Status410Result());
            }
        }