上传图片时,它会重定向到登录页面 [英] when uploading picture it redirect to login page

查看:172
本文介绍了上传图片时,它会重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用会话并且非常正常工作但是当我上传图片并按下按钮时它会重定向到login.aspx ...

不知道为什么会这样讨价还价



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

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();

          }
      }




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);

               }

           }


       }

推荐答案

'] 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();
ta sks();

}
}
'] 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(); } }




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);

               }

           }


       }


因为你的会话已经过期了。尝试在web.config文件中增加会话超时。



检查热门:使用Web.Config,IIS和global.asax在Asp.Net中设置会话TimeOut [ ^ ]



- Amit
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


这篇关于上传图片时,它会重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆