重建一个类文件,继承于page基类,有这个类文件来判断session
其他的页面这样继承这个类就行了。
详细如下:
pageset.cs
using System;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Configuration;
using personalization;
using System.Web.SessionState;
public class pageSet : Page
public class pageSet : Page
{
  public pageSet()
 {

 }    private void Page_Load(object sender, System.EventArgs e)
{

if(Object.Equals(Session["UserCode"],null))
{

Response.Redirect("../login.aspx");
}
   
 
}.....
其他的页面如:
a.aspx.cs
namespace oa
{
/// <summary>
/// usermanage 的摘要说明。
/// </summary>
public class a : pageSet
{



解决方案 »

  1.   

    我觉得最好的办法还是写在你那个单独的C#类的构造函数里面
    使用HttpContext.Current.Session["str"]进行session的判断,这样每个页面都可以访问到了
      

  2.   

    同意luofix(枯古)的看法,下面是我的实现:这是从前的代码,有点糙,不过思想是对的。
    可以把相同访问权的页面都放到同一个目录中,然后对这个目录在web.config进行权限设置。对web.config如下设置
    <configuration>
    <authentication mode="Forms">
    <forms name="YourApp" path="/" loginUrl="login.aspx" protection="All" timeout="30">
    </forms>
    </authentication>
    <location path="YourFolder">
    <system.web>
    <authorization>
    <allow roles="YourRoles" />
    <deny users="*" />
    </authorization>
    </system.web>
    </location>
    </configuration>在Global.asax.vb里面,
    If Not (HttpContext.Current.User Is Nothing) Then
    If (HttpContext.Current.User.Identity.IsAuthenticated = True) Then
                  If (HttpContext.Current.User.Identity.AuthenticationType = "Forms") Then
                        Dim id As FormsIdentity = CType(HttpContext.Current.User.Identity, FormsIdentity)
                        Dim ticket As FormsAuthenticationTicket = id.Ticket
                        ' Get the stored user-data, in this case, our roles
                        Dim userData As String = ticket.UserData
                        Dim roles() As String = userData.Split(",")
                        HttpContext.Current.User = New GenericPrincipal(id, roles)
                    End If
                End If
            End If在login.aspx.vb中
    Dim encryptPwd As String
            encryptPwd = Functions.EncryptPassword(txtpwd.Text, "MD5")
            Dim reader As SqlClient.SqlDataReader
            FormsAuthentication.Initialize()
            reader = Functions.GetReaderObject("SELECT name,roles FROM userinfo WHERE Username='" & txtloginid.Text & "' AND Password='" & encryptPwd & "'")
            If reader.Read Then
                FormsAuthentication.RedirectFromLoginPage(txtloginid.Text, False)
                Session("xm") = reader.Item(0)
                Dim sqldr As SqlDataReader
                sqldr = Functions.GetReaderObject("select distinct YYDX_CZ_BS from SysDefV_XT_QX_YH where YH_BS='" & txtloginid.Text & "'")
                Dim inttmp As Integer
                Dim objStrB As System.Text.StringBuilder = New System.Text.StringBuilder()
                While sqldr.Read
                    objStrB.Append(sqldr(0).ToString + ",")
                End While
                If sqldr.IsClosed = False Then
                    sqldr.Close()
                End If
                If objStrB.Length > 0 Then
                    objStrB.Remove(objStrB.Length - 1, 1)
                End If
                Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, txtloginid.Text, DateTime.Now, DateTime.Now.AddMinutes(30), True, objStrB.ToString, FormsAuthentication.FormsCookiePath)
                Dim hash As String = FormsAuthentication.Encrypt(ticket)
                Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, hash)
                Response.Cookies.Add(cookie)
            Else
                lblMsg.Text = "用户验证失败!"
                lblMsg.Visible = True
            End If
            If reader.IsClosed = False Then
                reader.Close()
            End If