public void ProcessRequest(HttpContext context) { try { if (context.Session != null) { if (context.Session["CurrentUser"] != null) { string urlRequested = HttpUtility.UrlDecode(context.Request.Url.AbsolutePath); string filePath = HttpContext.Current.Server.MapPath(urlRequested); FileInfo thisFileInfo = new FileInfo(filePath); string fileExtention = thisFileInfo.Extension; context.Response.AddHeader("Content-Length", thisFileInfo.Length.ToString()); //set content type DocumentTypeService documentTypesService = new DocumentTypeService(); DocumentType currentType = documentTypesService.ReadByExtension(fileExtention.Replace(".", "").ToLower()); if (fileExtention != null) { context.Response.ContentType = currentType.ContentType; } context.Response.TransmitFile(filePath); context.ApplicationInstance.CompleteRequest(); //context.Response.End(); } else { context.Response.Redirect("~/Login.aspx"); } } else { context.Response.Redirect("~/Login.aspx"); } } catch { context.Response.Redirect("~/Login.aspx"); } }
context.Response.AddHeader("Content-Length", thisFileInfo.Length.ToString());
FileInfo
Response.TransmitFile
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)