重建一个类文件,继承于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
{
}
}
其他的页面这样继承这个类就行了。
详细如下:
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
{
}
}
解决方案 »
- 为什么我添加用户或者添加角色App_Data文件夹里不会自动生成数据库文件??
- 在iis中设置了一个自定义的404页面,为什么点击不存在页面时,老是跳到搜搜网页上去了啊?
- GRIDVIEW自动生成列
- 如何利用js获取ajax控件PasswordStrength
- [下载]怎样调用Windows下载对话框
- window.Open('test.aspx?参数名=值','','height=250, width=400, top=0, left=0')
- 为什么我用window.open()打开一个新窗口总是只能开一个啊?
- 关于用户控件属性的使用?
- 怎么老是“非静态的字段、方法或属性“swust_life.Information.news”要求对象引用”呀?
- XmlTextReader读xml的问题
- 执行DataGrid_Update()时给参数赋值的问题
- asp中数据库的相对位置和绝对位置如何写?
使用HttpContext.Current.Session["str"]进行session的判断,这样每个页面都可以访问到了
可以把相同访问权的页面都放到同一个目录中,然后对这个目录在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