static void UrlRewriteModuleHttpRewriteInit(object sender, UrlRewriteEventArgs e) { // Before converting to internal URL, check if JSON mode should be enabled Global.UrlRewriteProvider.ConvertingToInternal += UrpConvertingToInternal; // After URL is converted to internal, check for JSON mode Global.UrlRewriteProvider.ConvertedToInternal += UrpConvertedToInternal; }
static void UrpConvertingToInternal(object sender, UrlRewriteEventArgs e) { if (e.Url.Path.ToLower().EndsWith("/json") || e.Url.Path.ToLower().EndsWith("/json/")) { UrlBuilder ub = new UrlBuilder(e.Url); Regex rgx = new Regex("[jJ][sS][oO][nN]/?"); ub.Path = rgx.Replace(ub.Path, string.Empty); ub.QueryCollection.Add("jsonPlugin", "true"); e.Url.Uri = ub.Uri; } }
static void UrpConvertedToInternal(object sender, UrlRewriteEventArgs e) { if (e.Internal is PageReference) { var localpath = HttpContext.Current.Server.MapPath(e.Url.Path); var rootFolder = HttpContext.Current.Server.MapPath("\\"); if (e.Url.Uri.PathAndQuery.Contains("jsonPlugin=true")) { UrlBuilder ub = new UrlBuilder(e.Url); ub.Path = "/JSONHandler.ashx"; e.Url.Uri = ub.Uri; } } }
private void HttpRewritingToInternal(object sender, UrlRewriteEventArgs e) { if (e.Url.Path.ToLower().EndsWith("sitemap.xml")) { var sitemap = sitemapRepository.GetSitemapData(e.Url.ToString()); if (sitemap != null) { HttpContext.Current.Items.Add(SitemapSessionKey, sitemap); e.UrlContext.InternalUrl.Path = "/Modules/Geta.SEO.Sitemaps/SitemapHandler.ashx"; e.IsModified = true; } } }
private void HttpRewriteInit(object sender, UrlRewriteEventArgs e) { var urm = (UrlRewriteModule)sender; urm.HttpRewritingToInternal += HttpRewritingToInternal; }
private static void UrlRewriteModuleHttpRewritingToInternal(object sender, UrlRewriteEventArgs e) { IEnumerable<ProviderSettings> providerSettings = Helpers.AmazonS3VirtualPathHelper.GetAllSettings(); if (!providerSettings.Any()) { return; } foreach (ProviderSettings providerSetting in providerSettings) { string virtualPath = Helpers.AmazonS3VirtualPathHelper.GetVirtualPath(providerSetting); if (e.Url.Path.StartsWith(virtualPath)) { var url = Helpers.AmazonS3VirtualPathHelper.GetBaseUrl(providerSetting); var path = e.Url.Path.Replace(virtualPath, string.Empty); var pathSplit = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); var folders = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries).ToList(); folders.Remove(pathSplit.Last()); var currentFolder = FolderEntity.GetChildFolders(1).First(n => n.Name == folders.First().ToString(CultureInfo.InvariantCulture)); foreach (var folder in folders) { if (currentFolder.PrimaryKeyId.HasValue) { foreach (var child in FolderEntity.GetChildFolders(currentFolder.PrimaryKeyId.Value)) { if (child.Name == folder) { currentFolder = child; } } } } if (currentFolder.PrimaryKeyId != null) { var folderElementEntities = FolderEntity.GetChildElements(currentFolder.PrimaryKeyId.Value); var imagename = folderElementEntities.First(a => a.Name == pathSplit.Last().ToString(CultureInfo.InvariantCulture)); Helpers.AmazonS3VirtualPathHelper.SetFileToPublic(providerSetting, imagename.BlobUid.ToString()); url = UriSupport.Combine(url, imagename.BlobUid.ToString()); } try { // Assuming url is the url to the S3 object. var buffer = new byte[1024 * 8]; // 8k buffer. var request = (HttpWebRequest)WebRequest.Create(url); var response = request.GetResponse(); int bytesRead = 0; HttpContext.Current.Response.ContentType = request.ContentType; using (var responseStream = response.GetResponseStream()) { while (responseStream != null && (bytesRead = responseStream.Read(buffer, 0, buffer.Length)) != 0) { HttpContext.Current.Response.OutputStream.Write(buffer, 0, bytesRead); } } } catch(WebException exception) { if (exception.Status == WebExceptionStatus.ProtocolError) { HttpContext.Current.Response.StatusCode = 403; } } HttpContext.Current.Response.End(); } } }
private static void HttpRewriteInit(object sender, UrlRewriteEventArgs e) { var urlRewriteModule = (UrlRewriteModule)sender; urlRewriteModule.HttpRewritingToInternal += UrlRewriteModuleHttpRewritingToInternal; }
private static void UrlRewriteModuleHttpRewritingToInternal(object sender, UrlRewriteEventArgs e) { IEnumerable<ProviderSettings> providerSettings = Helpers.AmazonS3VirtualPathHelper.GetAllSettings(); if (!providerSettings.Any()) { return; } foreach (ProviderSettings providerSetting in providerSettings) { string virtualPath = Helpers.AmazonS3VirtualPathHelper.GetVirtualPath(providerSetting); if (e.Url.Path.StartsWith(virtualPath)) { string url = Helpers.AmazonS3VirtualPathHelper.GetBaseUrl(providerSetting); string path = e.Url.Path.Replace(virtualPath, string.Empty); url = UriSupport.Combine(url, path); HttpContext.Current.Response.Redirect(url, true); } } }