public void Set(CacheControlType type, int seconds = -1) { CheckOptionalArgument(type, seconds); _type = type; _seconds = seconds; }
public static string GenerateMetaTag(string title, string description, string canonicalUrl, string googlePlusUrl, bool allowIndexPage, bool allowCache, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string applicationName = "web app", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private, bool allowTranslate = true) { title = title.Substring(0, title.Length <= MaxLenghtTitle ? title.Length : MaxLenghtTitle).Trim(); description = description.Substring(0, description.Length <= MaxLenghtDescription ? description.Length : MaxLenghtDescription).Trim(); var meta = ""; meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += string.Format("<title>{0}</title>\n", title); meta += string.Format( "<meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">"); if (!string.IsNullOrEmpty(googlePlusUrl)) { meta += string.Format("<link rel=\"author\" href=\"{0}\"/>\n", googlePlusUrl); } meta += string.Format("<link rel=\"canonical\" href=\"{0}\"/>\n", canonicalUrl); meta += string.Format("<link rel=\"shortcut icon\" href=\"{0}\" type=\"image/x-icon\" />\n", FaviconPath); meta += string.Format("<meta name=\"application-name\" content=\"{0}\" />\n", applicationName); meta += string.Format("<meta name=\"msapplication-config\" content=\"/browserconfig.xml\" />\n"); meta += string.Format("<meta http-equiv=\"content-language\" content=\"{0}\"/>\n", language); if (allowTranslate) { meta += string.Format("<meta name=\"google\" content=\"notranslate\" />\n"); } meta += string.Format("<meta name=\"description\" content=\"{0}\"/>\n", description); meta += string.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", EnumHelper.GetEnumDescription(typeof(CacheControlType), cacheControlType.ToString())); meta += string.Format("<meta name=\"robots\" content=\"{0}, {1}, {2}\" />\n", allowIndexPage ? "index" : "noindex", allowFollowLinks ? "follow" : "nofollow", allowCache ? "archive" : "noarchive"); meta += string.Format("<meta name=\"expires\" content=\"{0}\"/>\n", expires); if (!string.IsNullOrEmpty(lastmodified)) { meta += string.Format("<meta name=\"last-modified\" content=\"{0}\"/>\n", lastmodified); } if (!string.IsNullOrEmpty(author)) { meta += string.Format("<meta name=\"author\" content=\"{0}\"/>\n", author); } //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return(meta); }
public static string GetMemberValue(this CacheControlType type) { return(type switch { CacheControlType.MaxAge => "max-age", CacheControlType.MaxStale => "max-stale", CacheControlType.MinFresh => "min-fresh", CacheControlType.NoCache => "no-cache", CacheControlType.NoStore => "no-store", CacheControlType.NoTransform => "no-transform", CacheControlType.OnlyIfCached => "only-if-cached", _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) });
public static string GenerateMetaTag(string title, string description, string canonicalUrl, string googlePlusUrl, bool allowIndexPage, bool allowCache, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string applicationName = "web app", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private, bool allowTranslate = true) { title = title.Substring(0, title.Length <= MaxLenghtTitle ? title.Length : MaxLenghtTitle).Trim(); description = description.Substring(0, description.Length <= MaxLenghtDescription ? description.Length : MaxLenghtDescription).Trim(); var meta = ""; meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += string.Format("<title>{0}</title>\n", title); meta += string.Format( "<meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">"); if (!string.IsNullOrEmpty(googlePlusUrl)) meta += string.Format("<link rel=\"author\" href=\"{0}\"/>\n", googlePlusUrl); meta += string.Format("<link rel=\"canonical\" href=\"{0}\"/>\n", canonicalUrl); meta += string.Format("<link rel=\"shortcut icon\" href=\"{0}\" type=\"image/x-icon\" />\n", FaviconPath); meta += string.Format("<meta name=\"application-name\" content=\"{0}\" />\n", applicationName); meta += string.Format("<meta name=\"msapplication-config\" content=\"/browserconfig.xml\" />\n"); meta += string.Format("<meta http-equiv=\"content-language\" content=\"{0}\"/>\n", language); if (allowTranslate) meta += string.Format("<meta name=\"google\" content=\"notranslate\" />\n"); meta += string.Format("<meta name=\"description\" content=\"{0}\"/>\n", description); meta += string.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", EnumHelper.GetEnumDescription(typeof(CacheControlType), cacheControlType.ToString())); meta += string.Format("<meta name=\"robots\" content=\"{0}, {1}, {2}\" />\n", allowIndexPage ? "index" : "noindex", allowFollowLinks ? "follow" : "nofollow", allowCache ? "archive" : "noarchive"); meta += string.Format("<meta name=\"expires\" content=\"{0}\"/>\n", expires); if (!string.IsNullOrEmpty(lastmodified)) meta += string.Format("<meta name=\"last-modified\" content=\"{0}\"/>\n", lastmodified); if (!string.IsNullOrEmpty(author)) meta += string.Format("<meta name=\"author\" content=\"{0}\"/>\n", author); //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return meta; }
private static void CheckOptionalArgument(CacheControlType type, int seconds) { if (seconds <= -1) { switch (type) { case CacheControlType.MaxAge: case CacheControlType.MaxStale: case CacheControlType.MinFresh: throw new ArgumentException("You must supply an argument in seconds", nameof(type)); } } else { switch (type) { case CacheControlType.NoCache: case CacheControlType.NoStore: case CacheControlType.NoTransform: case CacheControlType.OnlyIfCached: throw new ArgumentException("You supplied seconds to a cache type that does not support it", nameof(type)); } } }
public static string GenerateMetaTag(string title, string description, bool allowIndexPage, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private) { title = title.Substring(0, title.Length <= MaxLengthTitle ? title.Length : MaxLengthTitle).Trim(); description = description.Substring(0, description.Length <= MaxLengthDescription ? description.Length : MaxLengthDescription).Trim(); var meta = ""; meta += $"<title>{title}</title>\n"; meta += $"<link rel=\"shortcut icon\" href=\"{FaviconPath}\"/>\n"; meta += $"<meta http-equiv=\"content-language\" content=\"{language}\"/>\n"; meta += string.Format("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"); meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += $"<meta name=\"description\" content=\"{description}\"/>\n"; meta += $"<meta http-equiv=\"Cache-control\" content=\"{((Enum)cacheControlType).GetEnumDescription()}\"/>\n"; meta += $"<meta name=\"robots\" content=\"{(allowIndexPage ? "index" : "noindex")}, {(allowFollowLinks ? "follow" : "nofollow")}\" />\n"; meta += $"<meta name=\"expires\" content=\"{expires}\"/>\n"; if (!string.IsNullOrEmpty(lastmodified)) { meta += $"<meta name=\"last-modified\" content=\"{lastmodified}\"/>\n"; } if (!string.IsNullOrEmpty(author)) { meta += $"<meta name=\"author\" content=\"{author}\"/>\n"; } //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return(meta); }
public static MvcHtmlString GenerateMetaTag(this HtmlHelper helper, string keyword, string description, bool allowIndexPage, bool allowFollowLinks, string author = "", string lastModified = "", string expires = "never", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private) { //const int maxLengthTitle = 60; const int maxLengthDescription = 170; //const string favIconPath = "~/cdn/ui/favicon.ico"; //title = title.Substring(0, title.Length <= maxLengthTitle ? title.Length : maxLengthTitle).Trim(); description = description.Substring(0, description.Length <= maxLengthDescription ? description.Length : maxLengthDescription).Trim(); var meta = ""; //meta += String.Format("<title>{0}</title>\n", title); //meta += String.Format("<meta http-equiv=\"content-language\" content=\"{0}\"/>\n", language); //meta += String.Format("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"); //meta += String.Format("<meta charset=\"utf-8\"/>\n"); meta += String.Format("<meta name=\"keyword\" content=\"{0}\"/>\n", keyword); meta += String.Format("<meta name=\"description\" content=\"{0}\"/>\n", description); meta += String.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", cacheControlType.GetDescription()); meta += String.Format("<meta name=\"robots\" content=\"{0}, {1}\" />\n", allowIndexPage ? "index" : "noindex", allowFollowLinks ? "follow" : "nofollow"); meta += String.Format("<meta name=\"expires\" content=\"{0}\"/>\n", expires); if (!String.IsNullOrEmpty(lastModified)) { meta += String.Format("<meta name=\"last-modified\" content=\"{0}\"/>\n", lastModified); } if (!String.IsNullOrEmpty(author)) { meta += String.Format("<meta name=\"author\" content=\"{0}\"/>\n", author); } //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return(new MvcHtmlString(meta)); }
public Upload WithCacheControl(CacheControlType type, int seconds = -1) { _request.CacheControl.Set(type, seconds); return(this); }
public void Reset() { _seconds = -1; _type = CacheControlType.Unknown; }