Click here to Skip to main content
15,896,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using session and very working fine but when i upload the picture and press button it redirect to login.aspx...
dont know why this is happing

C#
protected void Page_Load(object sender, EventArgs e)
      {


          string username = (string)(Session["UserAuthentication"]);
              if((Session["UserAuthentication"]!=null) && (!Page.IsPostBack))
              {
                  Label2.Text=username;

                string query ="SELECT Node,Title, Source, Scope, Criticality, Vendor, Dependancy, Status, [Start Week], ID, Resource FROM ['2013 Projects$'] WHERE Resource='" + username + "'";
                da = new SqlDataAdapter(query, connstring);
                dt = new DataTable();
                da.Fill(dt);
                GridView3.DataSource = dt;
                GridView3.DataBind();

              }
          else
              {
                  Response.Redirect("Login.aspx");
              }
          if (!Page.IsPostBack)
          {
              //data();
              tasks();

          }
      }

C#
protected void Button2_Click1(object sender, EventArgs e)
       {
           StartUpLoad();
       }
       private void StartUpLoad()
       {
           //get the file name of the posted image
           //   string username = (string)(Session["UserAuthentication"]);

              string imgName = "default.jpg";
           //sets the image path
           string imgPath = "Images/gallery/adil/" + imgName;

           //get the size in bytes that

           int imgSize = FileUpload1.PostedFile.ContentLength;

           //validates the posted file before saving
           if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
           {
               // 10240 KB means 10MB, You can change the value based on your requirement
               if (FileUpload1.PostedFile.ContentLength > 102400)
               {
                   Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);

               }
               else
               {
                   //then save it to the Folder
                   FileUpload1.SaveAs(Server.MapPath(imgPath));
                   Image1.ImageUrl = "~//" + imgPath;
                   Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);

               }

           }


       }
Posted

1 solution

Because your session is getting expired. Try increase the session timeout in web.config file.

Check Hot to : Set Session TimeOut In Asp.Net Using Web.Config, IIS and global.asax[^]

--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900