假设登录页是login.aspx
目标页是target.aspx
判断是否合法的函数IsLogined(username,password),合法返回true
用于存储是否登录的Session为Session["Logined"]
在target.aspx.cs中的Page_Load事件中
if(!Page.IsPostBack)
{
   if((bool)Session["Logined"]==true){
   }
   else
   {
      Response.Redirect("login.aspx?go=target.aspx");
    }
}
在login.aspx中
if(IsLogined(username,password)==true){   Session["Logined"]=true;
   Response.Redirect(Request["go"].ToString());
}
思路是这样的,还有好多细节,如判断Request["go"]是否为Null等

解决方案 »

  1.   

    using System;
    using System.Data;
    using System.Data.SqlClient;namespace BBS
    {
    public class BBSServer
    {
    private string m_strCon;
    private SqlConnection m_Con;

    //the property of connection string
    public string ConnectString
    {
    get
    {
    return m_strCon;
    }
    set
    {
    m_strCon = value;
    }
    }
    //connect 2 database 
    public void Connect2DB()
    {
    m_Con = new SqlConnection(m_strCon);
    m_Con.Open();
    }
    //Log Into the BBS
    public bool Login(string USER,string PSD)
    {       
    USER.TrimEnd();
    PSD.TrimEnd();
    string strSqlLogIn = "Select Count(*) as uCount from webuser where name ='" + USER + "' and psd ='" + PSD + "'";
    SqlCommand cmdLogIn = new SqlCommand(strSqlLogIn,m_Con);
    int count =(int) cmdLogIn.ExecuteScalar();
                            if (count == 0)
                                return false;
                            else
                                return true;
    }
    }
    }
      

  2.   

    在web.config里面设置
    <authentication mode="Forms"> 
    <forms name="yourname" loginUrl="Login.aspx" protection="All" timeout="10" path="/"/>
    </authentication><location path="Default.aspx">
    <system.web>
    <authorization>
    <deny users="?"/>
    </authorization>
    </system.web>
     </location>
      

  3.   

    truesight(快乐鼠标)的做法还是不错的
    大家还有详细的或者其他的方法吗?