c# - Session item always null in asp.net mvc3 -


the function upload image:

        [httppost]         public string uploadsingle(httppostedfilebase imagefile)     {         try         {             string filesavepath = server.mappath("~/content/temp/" +                imagefile.filename);             imagefile.saveas(filesavepath);              list<string> uploadedfile = (list<string>)httpcontext.session["uploadedfiles"];             if (uploadedfile == null)             {                 uploadedfile = new list<string>();             }              uploadedfile.add(filesavepath);             httpcontext.session["uploadedfiles"] = uploadedfile;             return "success";         }         catch (exception e)         {             return "error";         }     } 

this function work okay, image uploaded. when try see uploaded images.

 public string uploadresult()     {         list<string> uploadedfile = (list<string>)httpcontext.session["uploadedfiles"];          return uploadedfile.count + "";     } 

when debug, httpcontext.session["uploadedfiles"] return null. please give me help.

use httpcontext.current.session["uploadedfiles"] instead of httpcontext.session["uploadedfiles"]

httpcontext.current.session returns null if there no session available.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -