Roles in Authentication.

A

Andrew Banks

I've added the following to my global.asax file and am having problems with
the line highlighted by the ######'s

Can anyone offer any suggestions on this please? I've been working from a
poor VB example and have converted to C# the best I can.

Any help would be appreciated.

Thanks

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
SqlConnection con;
string sql;
SqlCommand cmd;
SqlDataReader reader;
string roles;
con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("Co
nnectionString"));
sql = "SELECT AdminID, AddAdmin FROM Admin WHERE AdminID = '" +
User.Identity.Name + "'";
cmd = new SqlCommand(sql, con);
con.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader["AddAdmin"].ToString()=="1")
roles = "Management";
else
roles = "Staff";
###############################
HttpContext.Current.User = new GenericPrincipal(User.Identity,
roles);
###############################
con.Close();
}
}
 
J

John Saunders

Andrew Banks said:
I've added the following to my global.asax file and am having problems with
the line highlighted by the ######'s

Can anyone offer any suggestions on this please? I've been working from a
poor VB example and have converted to C# the best I can.

Any help would be appreciated.

Thanks

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
SqlConnection con;
string sql;
SqlCommand cmd;
SqlDataReader reader;
string roles;
con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("Co
nnectionString"));
sql = "SELECT AdminID, AddAdmin FROM Admin WHERE AdminID = '" +
User.Identity.Name + "'";
cmd = new SqlCommand(sql, con);
con.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader["AddAdmin"].ToString()=="1")
roles = "Management";
else
roles = "Staff";
###############################
HttpContext.Current.User = new GenericPrincipal(User.Identity,
roles);
###############################
con.Close();
}
}

What problem are you having?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top