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

G

Guest

This is the code I like to see translated in C#, but I can't do it myself.
Can somebody help me with this one??


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
 
G

Guest

Hi,

I think that this is quite simple for you to do it yourself. Just follow the
syntax for C# and also how to declare variables and instantiate them.

Regards
M. Rajesh
..Net and Windows Shell MVP
www.winxpsolution.com.
 
M

Mike Bright MSP

Sjakie, don't have a compiler to hand to check this but:

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if(Request.IsAuthenticated)
{
SqlDataReader reader;

reader =
SqlHelper.ExecuteReader(connection_string,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);
}

}

Mmm, as I said no compiler to hand, so if it doesnt compile post back, b.t.w
this isn't really the place to post this, you should post this in the
C# newsgroups.

Regards

Mike Bright MCP, MSP

e:[email protected]
 
G

Guest

This is the only error I get:
Cannot implicitly convert type 'System.Array' to 'string[]'
 

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