Translating VB.NET-code into C#.NET + ASP.NET

G

Guest

VB.NET:

Sub Application_AuthenticateRequest(sender As Object, e As EventArgs)
If Request.IsAuthenticated Then
'Determine this user's roles
Dim reader As SqlDataReader = _
SqlHelper.ExecuteReader(connection string, _
CommandType.StoredProcedure, "rolesForUser", _
New SqlParameter("@username", User.Identity.Name))

' Create an array of role names
Dim roleList As New ArrayList
Do While reader.Read()
roleList.Add(reader("Name"))
Loop

'Convert the roleList ArrayList to a String array
Dim roleListArray As String() = roleList.ToArray(GetType(String))

'Add the roles to the User Principal
HttpContext.Current.User = _
New GenericPrincipal(User.Identity, roleListArray)
End If
End Sub


Thanx

e: (e-mail address removed)
 
Y

Your_name

using the excellent tool on developer fusion :

http://www.developerfusion.com/utilities/convertvbtocsharp.aspx

public void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Request.IsAuthenticated) {
SqlDataReader reader = SqlHelper.ExecuteReader(connectionstring,
CommandType.StoredProcedure, "rolesForUser", new SqlParameter
("@username", User.Identity.Name));
ArrayList roleList = new ArrayList();
while (reader.Read()) {
roleList.Add(reader("Name"));
}
string[] roleListArray = roleList.ToArray(typeof(string));
HttpContext.Current.User = new GenericPrincipal(User.Identity,
roleListArray);
}
}
 

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

Top