loginout.aspx.cs

来自「完成一个网上书店系统」· CS 代码 · 共 41 行

CS
41
字号
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class loginout : System.Web.UI.Page
{
    Class1 db = new Class1();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["UserName"].ToString() == "")
        {
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", "alert('您还没有登录,请先登录')", true);
           //加了下面这一句,弹不出警告对话框
           // Response.Redirect("login.aspx");
            Response.Write("<script>alert('您还没有登录,请先登录!');location.href='login.aspx';</script>");
        }
        else
        {
            Session["UserName"] = "";
            Session["Role"] = "";
            Session["UserID"] = "";
            Session["Role"] = "";

            //清空购物车记录
            db.ExecSql("delete from ShopCart");

            this.Page.Response.Redirect("favorite.aspx");
        }
        //Session.Abandon();//清空Session
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?