Exemple #1
0
        public ActionResult Index()
        {
            if (String.IsNullOrWhiteSpace(Pocket.UserLogin))
            {
                if (Request.Path.ToLower().Contains("/finance") || Request.Path.ToLower().Contains("/account/cabinet"))
                {
                    return(Redirect("/Account/Login"));
                }
            }

            var NameValueCollection = HttpUtility.ParseQueryString(Request.QueryString.ToString());

            foreach (string _key in NameValueCollection.AllKeys)
            {
                if (_key.Contains("utm_") || _key.Contains("_openstat") || _key.Contains("yclid") || _key.Contains("spush"))
                {
                    NameValueCollection.Remove(_key);
                }
            }
            string RequestQueryString = (NameValueCollection.Count > 0) ? "?" + NameValueCollection.ToString() : "";
            string RequestPath        = String.Format("{0}{1}", Request.Url.AbsolutePath, RequestQueryString);

            string ContentType = MimeMapping.GetMimeMapping(Request.Path).ToLower();

            if ((ContentType == "application/octet-stream" ||
                 ContentType == "text/html")
                &&
                ((Request.AcceptTypes.Length == 1 && Request.AcceptTypes[0] == "*/*") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "text/html") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "text/plain") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "application/xhtml+xml") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "application/xml")))
            {
                if (Pocket == null)
                {
                    return(Content(String.Format("Invalid pocket")));
                }
                else
                {
                    string content = Pocket.GetContent(RequestPath, false);

                    foreach (var ControlName in SharedControls)
                    {
                        if (content.Contains("@" + ControlName.Key))
                        {
                            string template = RenderRazorViewToString(ControlName.Value, Pocket);
                            content = content.Replace("@" + ControlName.Key, template);
                        }
                    }

                    if (String.IsNullOrWhiteSpace(Pocket.UserLogin))
                    {
                        content = content.Replace("href=\"/Account/Cabinet\"", "href=\"/Account/Login\"");
                        content = content.Replace("href=\"/Finance\"", "href=\"/Account/Login\"");
                    }
                    else
                    {
                        content = content.Replace("href=\"/Account/Register\">Регистрация</a>", "href=\"/Account/Logout\">Выйти</a>");
                    }

                    return(Content(content));
                }
            }
            else if (ContentType == "application/javascript" || ContentType == "text/css" || Request.AcceptTypes.Any(r => r.ToLower() == "text/css"))
            {
                string content = "";
                if (Pocket != null)
                {
                    content = Pocket.GetContent(RequestPath, true);
                }
                return(new FileContentResult(Encoding.UTF8.GetBytes(content), ContentType));
            }
            else
            {
                Stream Stream = new MemoryStream();
                if (Pocket != null)
                {
                    Stream = Pocket.GetSourceFileStream(RequestPath);
                }
                return(new FileStreamResult(Stream, ContentType));
            }
        }
Exemple #2
0
        public ActionResult Index()
        {
            string ContentType = MimeMapping.GetMimeMapping(Request.Path).ToLower();

            if ((ContentType == "application/octet-stream" ||
                 ContentType == "text/html")
                &&
                ((Request.AcceptTypes.Length == 1 && Request.AcceptTypes[0] == "*/*") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "text/html") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "text/plain") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "application/xhtml+xml") ||
                 Request.AcceptTypes.Any(r => r.ToLower() == "application/xml")))
            {
                NameValueCollection qscoll = HttpUtility.ParseQueryString(HttpContext.Request.Url.Query);
                if (qscoll.Count > 0)
                {
                    string source = qscoll["source"];
                    string id     = qscoll["id"];
                    if (source != null && id != null)
                    {
                        if (Pocket == null || id.ToLower() != Pocket.Id.ToString().ToLower())
                        {
                            SessionManager sm = new SessionManager();

                            string ServerFolderPath     = Server.MapPath("/");
                            string AllPocketsFolderPath = ConfigurationManager.AppSettings["PocketPath"];
                            if (!String.IsNullOrEmpty(AllPocketsFolderPath))
                            {
                                AllPocketsFolderPath = ServerFolderPath + AllPocketsFolderPath;
                            }
                            string      ServerDomainName = Request.Url.Authority;
                            PocketModel result           = new PocketModel(new Guid(id), source, AllPocketsFolderPath, ServerDomainName, ServerFolderPath, "", "");

                            sm.Set("pocketModel", result);

                            return(Redirect("/"));//плохое решение - лучше бы как-то удалять параметры
                        }
                    }
                }
                if (Pocket == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                string content = Pocket.GetContent(Request.Url, false);

                foreach (var ControlName in SharedControls)
                {
                    string template = RenderRazorViewToString(ControlName.Value, "");
                    content = content.Replace("@" + ControlName.Key, template);
                }

                return(Content(content));
            }
            else if (ContentType == "application/javascript" || ContentType == "text/css")
            {
                string content = "";
                if (Pocket != null)
                {
                    content = Pocket.GetContent(Request.Url, true);
                }
                return(new FileContentResult(Encoding.UTF8.GetBytes(content), ContentType));
            }
            else
            {
                Stream Stream = new MemoryStream();
                if (Pocket != null)
                {
                    Stream = Pocket.GetSourceFileStream(Request.Url);
                }
                return(new FileStreamResult(Stream, ContentType));
            }
        }