代码如下,高手帮帮忙啊,万分感激,剩下的分全部奉献出来了。using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DBCONN;
using System.Configuration;public partial class SiteMaster : System.Web.UI.MasterPage
{
public static int i =0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Convert.ToString(Session["usertype"]) == "")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["unlogin"];
Label1.Visible = false;
Label2.Visible = false;
LoginUser.Visible = false;
DropDownList1.Visible = false;
LogOut.Visible = false;
Response.Redirect("~/login.aspx");
}
if (Convert.ToString(Session["usertype"]) == "管理员")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["admin"];
Label1.Visible = true;
Label2.Visible = true;
LoginUser.Visible = true;
DropDownList1.Visible = true;
LogOut.Visible = true;
}
if (Convert.ToString(Session["usertype"]) == "报表用户")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["report"];
Label1.Visible = true;
Label2.Visible = true;
LoginUser.Visible = true;
DropDownList1.Visible = true;
LogOut.Visible = true;
}
}
if (!this.IsPostBack)
{
LoginUser.Text = Convert.ToString(Session["username"]);
string strConString = ConfigurationManager.ConnectionStrings["SFJWebSystem"].ConnectionString;
SqlConnection conn = new SqlConnection(strConString);
string strSQL = "select machine_name,conn_string from conn_string order by id";
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.Connection.Open();
SqlDataReader myReader = cmd.ExecuteReader();
while (myReader.Read())
{
DropDownList1.Items.Add(new ListItem(myReader["machine_name"].ToString(), myReader["conn_string"].ToString()));
}
cmd.Connection.Close();
DropDownList1.SelectedIndex = Convert.ToInt32(Session["dl1"]);
//将机台的连接字符串存入session以供其它无事件的页面使用
Session["conn_string_main"] = DropDownList1.SelectedValue;
}
} protected void Page_LoadComplete(object sender, EventArgs e)
{
i = i+1;
} public Label TheLable1
{
get { return Label1; }
set { Label1 = value; }
}
public Label TheLable2
{
get { return Label2; }
set { Label2 = value; }
}
public Label LogUser
{
get { return LoginUser; }
set { LoginUser = value; }
}
public DropDownList MachineID
{
get { return DropDownList1; }
set { DropDownList1 = value; }
}
public LinkButton LogQuit
{
get { return LogOut; }
set { LogOut = value; }
}
protected void LogOut_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Response.Redirect("~/login.aspx");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["dl1"] = DropDownList1.SelectedIndex;
DropDownList1.SelectedIndex = Convert.ToInt32(Session["dl1"]);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DBCONN;
using System.Configuration;public partial class SiteMaster : System.Web.UI.MasterPage
{
public static int i =0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Convert.ToString(Session["usertype"]) == "")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["unlogin"];
Label1.Visible = false;
Label2.Visible = false;
LoginUser.Visible = false;
DropDownList1.Visible = false;
LogOut.Visible = false;
Response.Redirect("~/login.aspx");
}
if (Convert.ToString(Session["usertype"]) == "管理员")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["admin"];
Label1.Visible = true;
Label2.Visible = true;
LoginUser.Visible = true;
DropDownList1.Visible = true;
LogOut.Visible = true;
}
if (Convert.ToString(Session["usertype"]) == "报表用户")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["report"];
Label1.Visible = true;
Label2.Visible = true;
LoginUser.Visible = true;
DropDownList1.Visible = true;
LogOut.Visible = true;
}
}
if (!this.IsPostBack)
{
LoginUser.Text = Convert.ToString(Session["username"]);
string strConString = ConfigurationManager.ConnectionStrings["SFJWebSystem"].ConnectionString;
SqlConnection conn = new SqlConnection(strConString);
string strSQL = "select machine_name,conn_string from conn_string order by id";
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.Connection.Open();
SqlDataReader myReader = cmd.ExecuteReader();
while (myReader.Read())
{
DropDownList1.Items.Add(new ListItem(myReader["machine_name"].ToString(), myReader["conn_string"].ToString()));
}
cmd.Connection.Close();
DropDownList1.SelectedIndex = Convert.ToInt32(Session["dl1"]);
//将机台的连接字符串存入session以供其它无事件的页面使用
Session["conn_string_main"] = DropDownList1.SelectedValue;
}
} protected void Page_LoadComplete(object sender, EventArgs e)
{
i = i+1;
} public Label TheLable1
{
get { return Label1; }
set { Label1 = value; }
}
public Label TheLable2
{
get { return Label2; }
set { Label2 = value; }
}
public Label LogUser
{
get { return LoginUser; }
set { LoginUser = value; }
}
public DropDownList MachineID
{
get { return DropDownList1; }
set { DropDownList1 = value; }
}
public LinkButton LogQuit
{
get { return LogOut; }
set { LogOut = value; }
}
protected void LogOut_Click(object sender, EventArgs e)
{
Session.RemoveAll();
Response.Redirect("~/login.aspx");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["dl1"] = DropDownList1.SelectedIndex;
DropDownList1.SelectedIndex = Convert.ToInt32(Session["dl1"]);
}
}
如果你的login.aspx页面也是引用了母版页的话,那么访问login.aspx就会不断的刷新,因为你跳转到login.aspx页面后,会执行母版页的
if (!IsPostBack)
{
if (Convert.ToString(Session["usertype"]) == "")
{
this.SiteMapDataSource1.Provider = System.Web.SiteMap.Providers["unlogin"];
Label1.Visible = false;
Label2.Visible = false;
LoginUser.Visible = false;
DropDownList1.Visible = false;
LogOut.Visible = false;
Response.Redirect("~/login.aspx");
}这时会判断session,发现用户没有登录,页面要跳转到login.aspx,引起死循环