桂林技术交流站,铜仁网站优化,南宁建设网站,开网店的流程和费用簡述 內容具體分為兩種分為上傳和下載部分#xff0c;服務搭載仍然選擇IIS#xff0c;內容還是相對簡單#xff0c;只是內部使用#xff0c;沒有使用太多的優化的技巧,net環境為4.7
上傳服務 上傳需要注意的是#xff0c;HttpPostedFileBase 不支持大文件傳輸#xff0…簡述 內容具體分為兩種分為上傳和下載部分服務搭載仍然選擇IIS內容還是相對簡單只是內部使用沒有使用太多的優化的技巧,net環境為4.7
上傳服務 上傳需要注意的是HttpPostedFileBase 不支持大文件傳輸文件達到几M的時候就會溢出所以需要修改web.config拓展到1g大小 system.webServerhandlersremove nameExtensionlessUrlHandler-Integrated-4.0 /remove nameOPTIONSVerbHandler /remove nameTRACEVerbHandler /add nameExtensionlessUrlHandler-Integrated-4.0 path*. verb* typeSystem.Web.Handlers.TransferRequestHandler preConditionintegratedMode,runtimeVersionv4.0 //handlerssecurityrequestFiltering!-- 单位字节(1000M) --requestLimits maxAllowedContentLength1048576000 //requestFiltering/security/system.webServersystem.webServerhttpProtocolcustomHeadersadd nameAccess-Control-Allow-Origin value* /add nameAccess-Control-Allow-Headers value* /add nameAccess-Control-Allow-Methods valueGET, POST, PUT, DELETE //customHeaders/httpProtocol/system.webServer 參考代碼如下 public string UploadFile(String project,String stage,string item,string mc,string type,string fileid, HttpPostedFileBase file){string msg ;if (file ! null file.ContentLength 0){// 返回成功消息msg 文件上传成功;}else{// 返回错误消息msg 请选择要上传的文件;}return msg;}
下載 下載部分更為簡單指定服務器的文件所在目錄可以非常簡單實現文件下載 public string download(String project, String stage, string item, string mc, string type, string fileid,string filename){//Uploads/ok2build/All/TI/SMT前段Process FMEA/通訊錄.xlsstring filePath Server.MapPath(~/Uploads/type/stage/mc/project/item/filename);//路径FileInfo fileinfo new FileInfo(filePath);Response.Clear(); //清除缓冲区流中的所有内容输出Response.ClearContent(); //清除缓冲区流中的所有内容输出Response.ClearHeaders(); //清除缓冲区流中的所有头Response.Buffer true; //该值指示是否缓冲输出并在完成处理整个响应之后将其发送Response.AddHeader(Content-Disposition, attachment;filename filename);Response.AddHeader(Content-Length, fileinfo.Length.ToString());Response.AddHeader(Content-Transfer-Encoding, binary);Response.ContentType application/unknow; //获取或设置输出流的 HTTP MIME 类型Response.ContentEncoding System.Text.Encoding.GetEncoding(gb2312); //获取或设置输出流的 HTTP 字符集Response.TransmitFile(filePath);return OK;}