当前位置: 代码迷 >> .NET相关 >> 登陆成功后,回到登陆前的网址和删除服务器图片
  详细解决方案

登陆成功后,回到登陆前的网址和删除服务器图片

热度:178   发布时间:2016-04-24 02:53:42.0
登陆成功后,返回登陆前的网址和删除服务器图片

登陆成功后,返回登陆前的网址

登陆前网站的cs的Page_Load方法中加入:

protected void Page_Load(object sender, EventArgs e)    {        Session.Add("url", Request.Url.ToString());    }

 

登录网站的cs登录成功后:

Response.Redirect(Session["url"].ToString());

 删除服务器图片

GridView1绑定数据库删除图片例子:

cs文件:

绑定数据库:

 

private string connStr = ConfigurationManager.ConnectionStrings["qiyesql"].ConnectionString;

 

删除服务器图片:

protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)    {        SqlConnection con = new SqlConnection(connStr);        con.Open();        SqlCommand com = new SqlCommand("select image from huandengyi where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'", con);        SqlDataReader dr = com.ExecuteReader();        if (dr.Read())        {            string path = HttpContext.Current.Server.MapPath("~/" + dr["image"].ToString());            if (File.Exists(path))            {                File.Delete(path);            }            else            {                Response.Write("<script>alert('图片不存在或已删除');</script>");            }        }        else        {            Response.Write("<script>alert('数据错误');</script>");        }    }

 

aspx GridView1里加入属性

 OnRowDeleting="GridView1_RowDeleting1"

 

1楼飞无痕落无声
一般不用session,这样用,http://xxxx.com/login.aspx?return_url=/index.aspx
Re: 李向宇
@飞无痕落无声,我的方法是当网页太多了 在模版页加入一个session就行了
  相关解决方案