将asp.net本页面转为静态页面html

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.message.Text = "";
        Head1.index = 3;
        Nav1.Nav = "登陆";
        this.Title = Common.Title + "会员登陆";
        if (!IsPostBack)
        {
            if (Request.QueryString["url"] != null)
                hid_url.Value = Request.QueryString["url"].ToString();
        }
    }

    protected void Btn_login_Click(object sender, ImageClickEventArgs e)//立即登入按钮
    {
        string username = this.username.Value;
        string pwd = this.pwd.Value;
        pwd = zhan.Normal.Common.CreatePassword(pwd, zhan.Enums.CurrentEnum.SecurityPassword.MD5).ToLower();

        string sql = "select * from tbl_member where username=@username and pwd=@pwd ";
        SqlParameter[] param ={
        new SqlParameter("@username",SqlDbType.VarChar,20),
        new SqlParameter("@pwd",SqlDbType.VarChar,100)
        };
        param[0].Value = username;
        param[1].Value = pwd;
        DataSet ds = zhan.Data.Sql.SqlHelper.ExecuteDataSet(CommandType.Text, sql, param);
        if (ds.Tables[0].Rows.Count == 1)
        {
            Session["mobile"] = ds.Tables[0].Rows[0]["mobile"].ToString();
            Session["memberid"] = ds.Tables[0].Rows[0]["id"].ToString();
            Session["nickname"] = ds.Tables[0].Rows[0]["nickname"].ToString();
            Session["username"] = ds.Tables[0].Rows[0]["username"].ToString();

            //自动登录
            if (chklogin.Checked)
            {
                Response.Cookies["member"]["mobile"] = ds.Tables[0].Rows[0]["mobile"].ToString();
                Response.Cookies["member"]["memberid"] = ds.Tables[0].Rows[0]["id"].ToString();
                Response.Cookies["member"]["nickname"] = ds.Tables[0].Rows[0]["nickname"].ToString();
                Response.Cookies["member"]["username"] = ds.Tables[0].Rows[0]["username"].ToString();
                Response.Cookies["member"].Expires = DateTime.Now.AddDays(1d);
            }

            //登录一次增加1个积分
            try
            {
                string msg = "";
                Common.DoPoint(int.Parse(ds.Tables[0].Rows[0]["id"].ToString()), 2, 0, out msg);
            }
            catch
            { }
            if (string.IsNullOrEmpty(hid_url.Value))
                Response.Redirect("Index.aspx");
            else
                Response.Redirect(hid_url.Value);
          
        }
        else
        {
            this.message.Text = "<script>alert('用户名号或密码错误');</script>";
        }
    }


    protected override void Render(HtmlTextWriter writer)
    {
        System.IO.StringWriter html = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter tw = new HtmlTextWriter(html);
        base.Render(tw);
        System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("index.html"), false, System.Text.Encoding.Default);
        sw.Write(html.ToString());
        sw.Close();
        tw.Close();
        //Response.Write("页面生成成功!");
        Response.Redirect("index.html");

    }
}

posted @ 2009-07-20 14:16  94cool  阅读(289)  评论(0)    收藏  举报