OK!这样可以了……谢谢!
using System;
using System.Data;
using System.Configuration;
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;
using System.Data.SqlClient;
/// <summary>
/// Class1 的摘要说明
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool CheckAuthority(int qx, string userId)//检查用户的权限
{
SqlConnection conn1 = new SqlConnection("data source=(local);database=****;user=sa; password=********"); //创建连接对象,并指明要连接的数据库名称、用户名、用户密码
SqlCommand orderCMD = new SqlCommand("Select Count(*) From relUserAndRole inner join relRoleAndAuthority on UserId=" + userId + " and relUserAndRole.RoleId=relRoleAndAuthority.RoleId" + " and qx_id=" + qx, conn1);
conn1.Open();
Int32 MyCount = (Int32)orderCMD.ExecuteScalar();
conn1.Close();
if (MyCount != 0)
{
return true;
}
else
{
return false;
}
}
}
---------------------------------------------------------------------
在其它*.cs页面中调用 Class1.cs 中的 Class1类的CheckAuthority方法
……
bool MyFlag = Class1.CheckAuthority(1, Session["userid"].ToString()); // 调用Class1类里面的CheckAuthority方法检查用户的权限
……