FLASH实现ASP.NET MVC上传---.NET篇
来源:互联网 发布:无基础学编程 知乎 编辑:程序博客网 时间:2024/04/30 07:42
其实在.NET MVC中保存图片最大的问题不是如何保存图片。而是身份验证。
为什么这样说,在firefox和Chrome中最大的问题是,flash作为插件出现。从而形成了两个终端。
在这种情况下,不同的useragent使用了不同的Cookie。
SessionID也就不同了,所以作为Session来验证用户的方式,显得有些不太可行。
那么,看下思路
修改SessionID的代码,在Global.asax中
protected void Application_BeginRequest(object sender, EventArgs e){try{string session_param_name = "ASPSESSID";string session_cookie_name = "ASP.NET_SessionId";if (HttpContext.Current.Request.Form[session_param_name] != null){SetCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);}else if (HttpContext.Current.Request.QueryString[session_param_name] != null){SetCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);}string auth_param_name = "AUTHID";string auth_cookie_name = FormsAuthentication.FormsCookieName;if (HttpContext.Current.Request.Form[auth_param_name] != null){SetCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);}else if (HttpContext.Current.Request.QueryString[auth_param_name] != null){SetCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);}}catch{}}private void SetCookie(string cookie_name, string cookie_value){HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);if (null == cookie){cookie = new HttpCookie(cookie_name);}cookie.Value = cookie_value;HttpContext.Current.Request.Cookies.Set(cookie);}
接受Flash上传代码
[HttpPost]public JsonResult SwfUploadImg(){try{//身份验证if (Session["auth"] == null){return Json(new { status = false, msg = "您尚未登陆!" });}//接受文件HttpPostedFileBase file = Request.Files["Filedata"];//是否文件为空if (file == null){return Json(new { status = false, msg = "上传文件为空!" });}//是否格式合法if (!Common.IsAuthorizedFile(file.FileName)){return Json(new { status = false, msg = "上传文件格式不合法!" });}//检查if (file.ContentLength >= Config.PicMaxSize){return Json(new { status = false, msg = "图片超过限制!" });}//文件重命名string file_name = Common.GetNewImgName(file.FileName);//保存图片file.SaveAs(Config.PicPath + file_name);//返回结果return Json(new { status = true, msg = "上传成功!", filename = file_name });}catch (Exception ex){return Json(new { status = false, msg = "异常错误" });Common.Log("SwfUploadImg",ex.Message);}}
以上只是我目前在使用的方案,如存在安全漏洞,还请指出!
FLASH实现ASP.NET MVC上传---Flash篇
1 0
- FLASH实现ASP.NET MVC上传---.NET篇
- FLASH实现ASP.NET MVC上传---Flash篇
- Asp.net MVC 实现图片上传剪切
- ASP.NET MVC实现多文件上传
- ASP.NET MVC 上传文件
- ASP.NET MVC - 文件上传
- asp.net MVC上传文件
- asp.net mvc文件上传
- ASP.NET MVC上传文件
- asp.net mvc文件上传
- ASP.NET MVC 图片上传
- asp.net mvc文件上传
- ASP.NET MVC上传文件
- asp.net和Flash结合实现文件上传
- 通过Flash实现ASP.NET多文件上传
- 通过Flash实现ASP.NET多文件上传
- [Flash FileUpload]用flash.net.FileReference实现ASP.NET无刷新文件上传
- [Flash FileUpload]用flash.net.FileReference实现ASP.NET无刷新文件上传
- json的中换行符的处理
- 马尔柯夫预测法
- 痔疮是什么呢?
- rac_grid自检提示缺少pdksh-5.2包
- select 1 from的浅析
- FLASH实现ASP.NET MVC上传---.NET篇
- AndroidAnnotations 是如何工作的
- UITabBarController
- Clojure Dev. on Eclipse
- 【cocos2d-html5、cocos2dx+jsbinding、cocos2dx-lua】
- git 远程分支同步
- 上机作业求三角形
- 求20个整数之和
- AndroidManifest.xml配置文件详解