public async Task <bool> AddRedirectAsync(URLRedirect newItem)
        {
            _context.Redirects.Add(newItem);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
 public static Document RedirectToDoc(URLRedirect r)
 {
     return(new Document()
     {
         { "Id", r.Id },
         { "UserId", r.UserId },
         { "DestinationUrl", r.DestinationUrl },
         { "NumVisits", r.NumVisits }
     });
 }
        public async Task <bool> AddRedirectAsync(URLRedirect r)
        {
            var request = new PutItemRequest
            {
                TableName = tableName,
                Item      = RedirectToDict(r)
            };
            await client.PutItemAsync(request);

            return(true);
        }
Exemple #4
0
        public static URLRedirect DictToRedirect(Dictionary <string, AttributeValue> vals)
        {
            var r = new URLRedirect
            {
                Id             = vals["Id"].S,
                UserId         = vals["UserId"].S,
                DestinationUrl = vals["DestinationUrl"].S,
                NumVisits      = long.Parse(vals["NumVisits"].N)
            };

            return(r);
        }
        public async Task <URLRedirect> VisitRedirectAsync(string Id)
        {
            URLRedirect item = await _context.Redirects
                               .Where(x => x.Id == Id)
                               .SingleOrDefaultAsync();

            if (item == null)
            {
                return(null);
            }
            item.NumVisits++;
            var saveResult = await _context.SaveChangesAsync();

            return(item);
        }
Exemple #6
0
 public static Dictionary <string, AttributeValue> RedirectToDict(URLRedirect r)
 {
     return(new Dictionary <string, AttributeValue>()
     {
         { "Id", new AttributeValue {
               S = r.Id
           } },
         { "UserId", new AttributeValue {
               S = r.UserId
           } },
         { "DestinationUrl", new AttributeValue {
               S = r.DestinationUrl
           } },
         { "NumVisits", new AttributeValue {
               N = r.NumVisits.ToString()
           } }
     });
 }
Exemple #7
0
        public async Task <IActionResult> AddRedirect(URLRedirect newRedirect)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }
            newRedirect.UserId = currentUser.UserID;
            var successful = await _redirectService.AddRedirectAsync(newRedirect);

            if (!successful)
            {
                return(BadRequest("Could not add item."));
            }
            return(RedirectToAction("Index"));
        }
Exemple #8
0
        private void CheckURLMapping()
        {
            lCMS   cCMS = new lCMS();
            string root = ClientScriptHelper.getURLRoot();

            // If the requested file exists
            HttpContext current = HttpContext.Current;

            current.Trace.Warn("ApplicationInstance", Context.ApplicationInstance.GetType().FullName);
            current.Trace.Warn("Request.Url", current.Request.Path.ToString());
            current.Trace.Warn("Request.RequestType", current.Request.RequestType);

            if (current.Request.RequestType == "" || !current.Request.PhysicalPath.EndsWith("\\404.aspx") && File.Exists(current.Request.PhysicalPath))
            {
                // Do nothing here, just serve the file
                current.Trace.Warn("File.Exists", "No hace nada");
            }
            // If the file does not exist then
            else
            {
                // Get the URL requested by the user
                string sRequestUrl = current.Request.Url.ToString().ToLower();
                if (sRequestUrl.Contains(".axd") || sRequestUrl.EndsWith(".gif") || sRequestUrl.EndsWith(".jpg") || sRequestUrl.EndsWith(".swf") || sRequestUrl.EndsWith(".bmp") || sRequestUrl.EndsWith(".ico") || sRequestUrl.EndsWith(".js"))
                {
                    return;
                }

                string[] aRequest   = current.Request.Url.ToString().Split(';');
                string   urlRequest = "";

                string sParameters   = "";
                string sRequestedURL = "";

                if (aRequest.Length > 1)
                {
                    urlRequest = aRequest[1].Substring(aRequest[1].IndexOf('/', 10));
                }
                else
                {
                    //sRequestedURL = Request.Path.Substring(1);
                    sRequestedURL = Request.Path;
                    sParameters   = current.Request.Url.Query;
                    if (sParameters != "")
                    {
                        sParameters = sParameters.Substring(1);
                    }
                }

                //if (sRequestedURL.EndsWith("/")) sRequestedURL = sRequestedURL.Substring(0, sRequestedURL.Length - 1);
                if (sRequestedURL.StartsWith(root))
                {
                    sRequestedURL = sRequestedURL.Substring(root.Length);
                }
                //sRequestedURL = urlRequest.Substring(1);

                // You can retrieve the ID of the content from database that is
                // relevant to this requested URL (as per your business logic)

                current.Trace.Warn("sRequestedURL", sRequestedURL);
                current.Trace.Warn("sParameters", sParameters);
                string sTargetURL = "Content/Index.aspx"; //Change to Page Not Found: ERROR 404


                string sURLnew = URLRedirect.Get301(sRequestedURL);
                if (sURLnew != sRequestedURL)
                {
                    ClientScriptHelper.Redirect301(this.Context, root + sURLnew);
                    sRequestedURL = sURLnew;
                }
                string Registro = (Request["registro"] != null) ? (Request["registro"]).ToString() : "";
                if (Registro == "true")
                {
                    sRequestedURL = "registro";
                }
                switch (sRequestedURL)
                {
                case "": sTargetURL = "Content/Index.aspx"; break;

                //case "productos/producto_item": sTargetURL = "Content/ProductoItem.aspx?idproducto=" + IdProducto; break;
                case "producto_wishlist": sTargetURL = "Content/ProductoWishlist.aspx"; break;

                case "producto_compras": sTargetURL = "Content/ProductoCompras.aspx"; break;

                case "registro": sTargetURL = "Content/Registro.aspx"; break;

                case "home": sTargetURL = "Content/Index.aspx"; break;

                case "admin": sTargetURL = "Admin/Index/login.aspx"; break;

                case "despacho": sTargetURL = "Content/Despacho.aspx"; break;

                case "verificar": sTargetURL = "Content/Verificar.aspx"; break;

                case "cuenta": sTargetURL = "Content/Cuenta.aspx"; break;

                case "cuenta_detalle": sTargetURL = "Content/CuentaDetalle.aspx"; break;

                case "direccion_despacho": sTargetURL = "Content/DireccionDespacho.aspx"; break;

                case "historial_pedidos": sTargetURL = "Content/Historial_Pedidos.aspx"; break;

                case "confirmacion_visanet": sTargetURL = "Content/Gracias-compra.aspx"; break;

                case "direccion": sTargetURL = "Content/Direccion.aspx"; break;

                case "direccionfancybox": sTargetURL = "Content/DireccionFancybox.aspx"; break;

                case "restablecer-contrasena": sTargetURL = "Content/PagRestablecer-Contrasena.aspx"; break;

                case "libro-reclamaciones": sTargetURL = "Content/Libro_Reclamaciones.aspx"; break;

                case "libro-reclamaciones-detalle": sTargetURL = "Content/Libro_Reclamaciones_Detalle.aspx"; break;

                case "libro-reclamaciones-gracias": sTargetURL = "Content/Libro_Reclamaciones_Gracias.aspx"; break;

                case "job": sTargetURL = "Content/job.aspx"; break;

                default:
                    if (sRequestedURL.Contains("/"))
                    {
                        eArticulo oArticulo = new eArticulo();

                        int IDPagina = cCMS.Articulo_item(sRequestedURL);
                        if (IDPagina > 0)
                        {
                            sTargetURL = "Content/Index.aspx?aID=" + IDPagina.ToString();
                        }
                        else
                        {
                            sTargetURL = Error404(sTargetURL);
                        }
                    }
                    else
                    {
                        eMenuWebDetalle eMenuWebDetalle = new eMenuWebDetalle();

                        int IDSeccion = cCMS.MenuWebDetalle_item(sRequestedURL);
                        if (IDSeccion > 0)
                        {
                            sTargetURL = "Content/Index.aspx?mwID=" + IDSeccion.ToString();
                        }
                        else
                        {
                            sTargetURL = Error404(sTargetURL);
                        }
                    }
                    break;
                }

                if (sParameters != "")
                {
                    sTargetURL += (sTargetURL.Contains("?") ? "&" : "?") + sParameters;
                }

                current.Trace.Warn("sTargetURL", sTargetURL);

                // Owing to RewritePath, the user will see requested URL in the address bar
                // The second argument should be false, to keep your references
                // to images, css files
                Context.RewritePath(root + sTargetURL, false);
            }
        }
Exemple #9
0
        public async Task <bool> AddRedirectAsync(URLRedirect r)
        {
            await context.SaveAsync(r);

            return(true);
        }