• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Transalate Code vb.net C#

Can someone help me translating this piece of code into C#, is for a simple login page using session, thanks in advance...!
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        '  If HttpContext.Current.User.Identity.IsAuthenticated Then
        If Session("Admin") = False Then
            Response.Redirect("default.aspx")

        End If

    End Sub

Open in new window

0
TonyReba
Asked:
TonyReba
1 Solution
 
RickCommented:
// if (HttpContext.Current.User.Identity.IsAuthenticated) {

   if (Session["Admin"] == false) {
      Response.Redirect("default.aspx");

   }

// }

0
 
Carl TawnSystems and Integration DeveloperCommented:
Not much different in C# to be honest (although i've added a bit of sanity checking for good measure):
protected void Page_Init(object sender, System.EventArgs e)
{
        '  If HttpContext.Current.User.Identity.IsAuthenticated Then
        if (Session["Admin"] != null && bool.Parse(Session["Admin"]) == false)
        {
            Response.Redirect("default.aspx")
        }
}

Open in new window

0
 
Paul JacksonCommented:
protected void Page_Init(object sender, System.EventArgs e)
{

	//  If HttpContext.Current.User.Identity.IsAuthenticated Then 
	if (Session("Admin") == false) {
		Response.Redirect("default.aspx");

	}

}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DhaestCommented:
A free online convertor: http://www.developerfusion.com/tools/convert/vb-to-csharp/

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        '  If HttpContext.Current.User.Identity.IsAuthenticated Then
        If Session("Admin") = False Then
            Response.Redirect("default.aspx")

        End If

    End Sub

Open in new window

0
 
DhaestCommented:
Pasted the wrong code ... :)
0
 
RickCommented:
The whole code:
protected void Page_Init(object sender, EventArgs e) {

   // if (HttpContext.Current.User.Identity.IsAuthenticated) {

       if (Session["Admin"] == false) {
        Response.Redirect("default.aspx");
       }

   // }

}

Open in new window

0
 
Asim NazirCommented:
You can always use following converter to convert from VB to C# or conversely
http://www.developerfusion.com/tools/convert/vb-to-csharp/
0
 
TonyRebaAuthor Commented:
I am getting the folllowing error :

Operator ==  cannot be applied to operands of type object and bool
0
 
Alfred A.Commented:
Try this:
protected void Page_Init(object sender, EventArgs e)
        {
            // if (HttpContext.Current.User.Identity.IsAuthenticated) {

            if ((bool)Session["Admin"] == false)
            {
                Response.Redirect("default.aspx");
            }
        }

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now