Flash implementation of ASP. NET MVC upload---.

Source: Internet
Author: User
Tags setcookie

actually save the picture in. NET MVC Maximum The problem is not how to save the picture. But authentication .

The biggest problem with Firefox and Chrome is that flash as Plugins appear. Thus formed two terminals.

in this case, different useragent use different Cookies .

SessionID is different, so as the session to verify the user's way, it seems that some is not feasible.

Well, look at the idea.


Modify the code for SessionID, in 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);} Cookies. Value = Cookie_value;  HttpContext.Current.Request.Cookies.Set (cookie);}

Accept Flash Upload Code

[Httppost]public jsonresult swfuploadimg () {try{//authentication if (session["auth"] = = null) {return Json (new {status = False, Msg = "You haven't logged in yet!" " });} Accept files HttpPostedFileBase file = request.files["Filedata"];//if the file is null if (file = = null) {return Json (new {status = False, MSG = "The upload file is empty!" " });} Whether the format is valid if (! Common.isauthorizedfile (file. FileName) {return Json (new {status = False, msg = "The upload file format is not valid!") " });} Check if (file. ContentLength >= config.picmaxsize) {return Json (new {status = False, msg = "Picture exceeds limit!) " });} File Rename string file_name = Common.getnewimgname (file. FileName);//Save picture file. SaveAs (Config.picpath + file_name);//Returns the result return Json (new {status = True, msg = "Upload succeeded!) ", filename = file_name});} catch (Exception ex) {return Json (new {status = False, msg = "Exception error"}); Common.Log ("Swfuploadimg", ex. Message);}}

The above is only my current use of the scheme, such as the existence of security loopholes, please also point out!

Flash implementation of ASP. NET MVC upload---Flash article


Flash implementation of ASP. NET MVC upload---.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.