checking to see if user is authenticated

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am learning C# and basically using a .asp net app I wrote in VB and
converting to C#.

in VB code :


If Context.User.Identity.IsAuthenticated Then
obj = Session.Item(SESSION_NAVIGATION_DATA)
Else
obj = Page.Cache.Get(CACHE_NAVIGATION_DATA)
End If

this code checks to see if for the current user they have already been
authenticated.

my problem is that when trying to write the first line in C# my intellisence
does not provide me with any methods or properites.

I am "inheriting and implementing" all my assembly (DLL) libraries I need.
HELP says that "The Context type supports the .NET Framework infrastructure
and is not intended to be used directly from your code.

How then do I do in C# that I am doing in VB.NET?

thanks

Chris
 
By first line… do you mean the if statement? I ask because when I convert
your VB.NET code to C# and run it, it gives me no problems. This is what I’ve
got it as in C#, what does yours look like?

if( Context.User.Identity.IsAuthenticated )
{
obj = Session[SESSION_NAVIGATION_DATA];
}
else
{
obj = Page.Cache[CACHE_NAVIGATION_DATA];
}

Brendan
 
Hi Brendan,

well i actually have'nt tried to run the code yet, I just know i'm not
getting any intellisence. Is it necessary to see the intellisence?

Brendan Grant said:
By first line… do you mean the if statement? I ask because when I convert
your VB.NET code to C# and run it, it gives me no problems. This is what I’ve
got it as in C#, what does yours look like?

if( Context.User.Identity.IsAuthenticated )
{
obj = Session[SESSION_NAVIGATION_DATA];
}
else
{
obj = Page.Cache[CACHE_NAVIGATION_DATA];
}

Brendan


Chris said:
Hi,

I am learning C# and basically using a .asp net app I wrote in VB and
converting to C#.

in VB code :


If Context.User.Identity.IsAuthenticated Then
obj = Session.Item(SESSION_NAVIGATION_DATA)
Else
obj = Page.Cache.Get(CACHE_NAVIGATION_DATA)
End If

this code checks to see if for the current user they have already been
authenticated.

my problem is that when trying to write the first line in C# my intellisence
does not provide me with any methods or properites.

I am "inheriting and implementing" all my assembly (DLL) libraries I need.
HELP says that "The Context type supports the .NET Framework infrastructure
and is not intended to be used directly from your code.

How then do I do in C# that I am doing in VB.NET?

thanks

Chris
 
Does the code compile?
I think my question would be: In what method (and what class) are you
writing this code?
That class must be inheriting (directly or indirectly) from the Control
class in order to have the Context property and therefore be compilable and
have Intellisense support.


Chris said:
Hi Brendan,

well i actually have'nt tried to run the code yet, I just know i'm not
getting any intellisence. Is it necessary to see the intellisence?

Brendan Grant said:
By first line. do you mean the if statement? I ask because when I convert
your VB.NET code to C# and run it, it gives me no problems. This is what
I've
got it as in C#, what does yours look like?

if( Context.User.Identity.IsAuthenticated )
{
obj = Session[SESSION_NAVIGATION_DATA];
}
else
{
obj = Page.Cache[CACHE_NAVIGATION_DATA];
}

Brendan


Chris said:
Hi,

I am learning C# and basically using a .asp net app I wrote in VB and
converting to C#.

in VB code :


If Context.User.Identity.IsAuthenticated Then
obj = Session.Item(SESSION_NAVIGATION_DATA)
Else
obj = Page.Cache.Get(CACHE_NAVIGATION_DATA)
End If

this code checks to see if for the current user they have already been
authenticated.

my problem is that when trying to write the first line in C# my
intellisence
does not provide me with any methods or properites.

I am "inheriting and implementing" all my assembly (DLL) libraries I
need.
HELP says that "The Context type supports the .NET Framework
infrastructure
and is not intended to be used directly from your code.

How then do I do in C# that I am doing in VB.NET?

thanks

Chris
 
here is all my code exactly :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace BBAdmin.Pages
{

public class leftnav : System.Web.UI.Page
{
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)

{
RegisterLinkButtonScript();
}

public static string GetJSHyperlinksString()
{
//this function will determine the hyperlinks available to the logged
//in user by reading the database. Default hyperlinks are constructed
//for those who are not logged in.

object objsession;
string JSHyperlinksString = string.Empty;

//check to see if the hyperlinks already exist.
//this javascript code is parsed by the worker thread into an
//unmanaged client side code whenever it is retrieved by the
//page.cache.get method
if( Context.User.Identity.IsAuthenticated )
{
objsession = Session[SESSION_NAVIGATION_DATA];
}
else
{
objsession = Page.Cache[CACHE_NAVIGATION_DATA];
}




return JSHyperlinksString;
}
}
}

Francois Bonin said:
Does the code compile?
I think my question would be: In what method (and what class) are you
writing this code?
That class must be inheriting (directly or indirectly) from the Control
class in order to have the Context property and therefore be compilable and
have Intellisense support.


Chris said:
Hi Brendan,

well i actually have'nt tried to run the code yet, I just know i'm not
getting any intellisence. Is it necessary to see the intellisence?

Brendan Grant said:
By first line. do you mean the if statement? I ask because when I convert
your VB.NET code to C# and run it, it gives me no problems. This is what
I've
got it as in C#, what does yours look like?

if( Context.User.Identity.IsAuthenticated )
{
obj = Session[SESSION_NAVIGATION_DATA];
}
else
{
obj = Page.Cache[CACHE_NAVIGATION_DATA];
}

Brendan


:

Hi,

I am learning C# and basically using a .asp net app I wrote in VB and
converting to C#.

in VB code :


If Context.User.Identity.IsAuthenticated Then
obj = Session.Item(SESSION_NAVIGATION_DATA)
Else
obj = Page.Cache.Get(CACHE_NAVIGATION_DATA)
End If

this code checks to see if for the current user they have already been
authenticated.

my problem is that when trying to write the first line in C# my
intellisence
does not provide me with any methods or properites.

I am "inheriting and implementing" all my assembly (DLL) libraries I
need.
HELP says that "The Context type supports the .NET Framework
infrastructure
and is not intended to be used directly from your code.

How then do I do in C# that I am doing in VB.NET?

thanks

Chris
 
Back
Top