static public int FileUploadMaxSize() { int maxRequestLength = 0; System.Web.Configuration.HttpRuntimeSection section = System.Configuration.ConfigurationManager.GetSection("system.web/httpRuntime") as System.Web.Configuration.HttpRuntimeSection; if (section != null) { maxRequestLength = section.MaxRequestLength; } return(maxRequestLength); }
/// <summary> /// Gets the maximum request length from the configuration settings. /// </summary> /// <param name="context">Http context.</param> /// <returns>The maximum request length (in kb).</returns> int GetMaxRequestLength(HttpContext context) { int DEFAULT_MAX = 4096; // Look up the config setting System.Web.Configuration.HttpRuntimeSection config = context.GetSection("system.web/httpRuntime") as System.Web.Configuration.HttpRuntimeSection; if (config == null) { return(DEFAULT_MAX); // None found. Return 4096Kb which is the default setting. } else { return(config.MaxRequestLength); } }
static HttpRuntime () { firstRun = true; try { WebConfigurationManager.Init (); SettingsMappingManager.Init (); runtime_section = (HttpRuntimeSection) WebConfigurationManager.GetSection ("system.web/httpRuntime"); } catch (Exception ex) { initialException = ex; } // The classes in whose constructors exceptions may be thrown, should be handled the same way QueueManager // and TraceManager are below. The constructors themselves MUST NOT throw any exceptions - we MUST be sure // the objects are created here. The exceptions will be dealt with below, in RealProcessRequest. queue_manager = new QueueManager (); if (queue_manager.HasException) { if (initialException == null) initialException = queue_manager.InitialException; else { Console.Error.WriteLine ("Exception during QueueManager initialization:"); Console.Error.WriteLine (queue_manager.InitialException); } } trace_manager = new TraceManager (); if (trace_manager.HasException) { if (initialException == null) initialException = trace_manager.InitialException; else { Console.Error.WriteLine ("Exception during TraceManager initialization:"); Console.Error.WriteLine (trace_manager.InitialException); } } registeredAssemblies = new SplitOrderedList <string, string> (StringComparer.Ordinal); cache = new Cache (); internalCache = new Cache (); internalCache.DependencyCache = internalCache; do_RealProcessRequest = new WaitCallback (state => { try { RealProcessRequest (state); } catch {} }); end_of_send_cb = new HttpWorkerRequest.EndOfSendNotification (EndOfSend); }
public void ProcessRequest(HttpContext context) { string sourceFilePath = string.Empty; string detailFilePath = string.Empty; System.Web.Configuration.HttpRuntimeSection m_RuntimeSection = new HttpRuntimeSection(); //* The maximum request size in kilobytes. The default size is 4096 KB (4 MB) int maxFileSize = 4; if (context.Request.ContentLength > maxFileSize * 1024 * 1024) // maxFileSize 4 MB - System.Web.Configuration { context.Response.Write("_Maximum request length exceeded!"); return; } if (context.Request.Files.Count > 0) { SigmaResultType result = new SigmaResultType(); HttpFileCollection files = context.Request.Files; string mobileLoginId = context.Request.Form["MobileLoginId"]; string mobileUdId = context.Request.Form["MobileUdId"]; string relationTable = context.Request.Form["RelationTable"]; string fileName = context.Request.Form["FileName"]; string filePath = context.Request.Form["FilePath"]; string rootPath = "/SigmaStorage/"; //각 FileType에 따른 저장경로를 가져옴 //rootPath = GetRootPath(fileType); //childPath = GetChildPath(fileType); string saveFullPath = rootPath + filePath; foreach (string key in files) { HttpPostedFile file = files[key]; string connStr = ConnStrHelper.getDbConnString(); if (!System.IO.Directory.Exists(saveFullPath)) { System.IO.Directory.CreateDirectory(saveFullPath); } string filename = System.IO.Path.GetFileName(file.FileName); sourceFilePath = System.IO.Path.Combine(saveFullPath, filename); string fileExtention = Path.GetExtension(sourceFilePath); file.SaveAs(sourceFilePath); file.InputStream.Dispose(); detailFilePath = saveFullPath + filename; UploadFileHistoryInfoDTO uploadFileHistoryInfoDTO = new UploadFileHistoryInfoDTO(); DataSync dataSync = new DataSync(); uploadFileHistoryInfoDTO.FileName = fileName; uploadFileHistoryInfoDTO.FilePath = filePath; uploadFileHistoryInfoDTO.RelationTable = relationTable; uploadFileHistoryInfoDTO.MobileLoginId = mobileLoginId; uploadFileHistoryInfoDTO.MobileUdId = mobileUdId; dataSync.AddUploadFileHistoryInfo(uploadFileHistoryInfoDTO); } } context.Response.ContentType = "text/plain"; context.Response.Write("Success"); }
public HttpRuntimeSettings(HttpRuntimeSection httpRuntimeSection) { if (httpRuntimeSection == null) throw new ArgumentNullException("httpRuntimeSection"); _httpRuntimeSection = httpRuntimeSection; }
// Upload File public void ProcessRequest(HttpContext context) { string sourceFilePath = string.Empty; string detailFilePath = string.Empty; System.Web.Configuration.HttpRuntimeSection m_RuntimeSection = new HttpRuntimeSection(); //* The maximum request size in kilobytes. The default size is 4096 KB (4 MB) //context.Response.Write(m_RuntimeSection.MaxRequestLength.ToString() + "<br>"); //if (context.Request.Params["maxFileSize"] != null) // int.TryParse(context.Request.Params["maxFileSize"], out maxFileSize); int maxFileSize = 4; if (context.Request.ContentLength > maxFileSize * 1024 * 1024) // maxFileSize 4 MB - System.Web.Configuration { context.Response.Write("_Maximum request length exceeded!"); return; } if (context.Request.Files.Count > 0) { SigmaResultType result = new SigmaResultType(); HttpFileCollection files = context.Request.Files; //HttpPostedFile file = context.Request.Files["file"]; string fileType = context.Request.Form["name"]; //fileType 종류 "ImportList" --> saveFullPath 전송, "DrawingImage" --> childPath Directory 전송, "HRImage" --> saveFullPath 전송 string rootPath = string.Empty; string childPath = string.Empty; //각 FileType에 따른 저장경로를 가져옴 rootPath = GetRootPath(fileType); childPath = GetChildPath(fileType); string saveFullPath = rootPath + childPath; foreach (string key in files) { HttpPostedFile file = files[key]; //FileStream fileToupload = new FileStream(saveFullPath + file.FileName, FileMode.Create); //byte[] bytearray = new byte[10000]; //int bytesRead, totalBytesRead = 0; //do //{ // bytesRead = file.InputStream.Read(bytearray, 0, bytearray.Length); // totalBytesRead += bytesRead; //} while (bytesRead > 0); //fileToupload.Write(bytearray, 0, bytearray.Length); //fileToupload.Close(); //fileToupload.Dispose(); string connStr = ConnStrHelper.getDbConnString(); if (!System.IO.Directory.Exists(saveFullPath)) { System.IO.Directory.CreateDirectory(saveFullPath); } //--------------- IE - The given path's format is not supported. error 해결 ------------------------- // IE : 선택 File.확장자의 전체 경로가 넘어오는 경우 // Crome : 선택 File.확장자만 넘어오는 경우 // File Name.확장자 만 필요함 string filename = System.IO.Path.GetFileName(file.FileName); sourceFilePath = System.IO.Path.Combine(saveFullPath, filename); //----------------------------------------------------------------------------------------------------- //sourceFilePath = saveFullPath + file.FileName; string fileExtention = Path.GetExtension(sourceFilePath); // File .pdf 만 등록 가능하도록 변경. if (fileType == "DrawingImage") { if (fileExtention == ".pdf" || fileExtention == ".PDF") { } else { // _ 붙으면 Client 화면에서 _다음 Text 를 Error Message로 인식하기로 한다. context.Response.ContentType = "text/plain"; context.Response.Write("_Upload Only [PDF] File!"); return; } } file.SaveAs(sourceFilePath); file.InputStream.Dispose(); detailFilePath = childPath + filename; } // Upload 결과에 대해 Return - Upload File Path: context.Response.ContentType = "text/plain"; //context.Response.Write("File(s) uploaded successfully!"); switch (fileType) { case "DrawingImage": //"DrawingImage" --> childPath Directory 전송, context.Response.Write(detailFilePath); break; default: //"ImportList" --> saveFullPath 전송, "HRImage - Photo, Logo" --> saveFullPath 전송 context.Response.Write(detailFilePath); break; } } }