After successful login, return to the pre-login URL and delete server images, server Images

Source: Internet
Author: User

After successful login, return to the pre-login URL and delete server images, server Images

After successful login, return to the pre-login URL

Add:

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

 

After successfully logging on to the website's cs:

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

Delete server Images

Example of how to bind GridView1 to a database and delete an image:

Cs file:

BIND database:

 

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

 

Delete server images:

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 ('image does not exist or deleted '); </script>") ;}} else {Response. write ("<script> alert ('data error'); </script> ");}}

 

Add attributes to aspx GridView1

 OnRowDeleting="GridView1_RowDeleting1"

 

Related Article

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.