Forms验证角色授权无效?郁闷两天了
角色授权的代码如下:
void Application_AuthenticateRequest(object sender,EventArgs e)
{
if (this.Request.IsAuthenticated)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "ServerGLKJConnectionString "].ConnectionString);
SqlCommand comm = new SqlCommand();
try
{
comm.Connection = conn;
comm.CommandText = "SELECT MemberInRole.RoleIndentifier FROM MemberInRole,Members where Members.MemberID=MemberInRole.MemberID AND Members.Email= ' "+User.Identity.Name.ToString()+ " ' ";
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
StringCollection roles = new StringCollection();
while(reader.Read())
{
roles.Add(reader[0].ToString());
}
string[] rolesArr = new String[roles.Count];
roles.CopyTo(rolesArr, 0);
this.Context.User = new System.Security.Principal.GenericPrincipal(this.User.Identity, rolesArr);
}
catch (SqlException ex)
{
throw ex;