473,758 Members | 8,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Context.User problem

I am playing with GenericPrincipa l classes and am using a sample program to
test it.

The problem is that even though I set the roles (which shows the roles in
the Context.User as being there), when the program goes from the login page
to the next page - the roles in the Context.User is empty.

My Login page is:

*************** *************** *************** *************** *****
private void btnAuthenticate _Click(object sender, System.EventArg s e)
{
if(txtUserName. Text == "Adam" &&
txtPassword.Tex t == "Dinosaur")
{
string[] roles = {"Admin", "User"};
DoAuthenticate( txtUserName.Tex t, roles);
}

if(Context.User .Identity.IsAut henticated )
{
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
false);
}
}
private void DoAuthenticate (string userName, string[] roles)
{
GenericIdentity userIdentity = new GenericIdentity (userName);
GenericPrincipa l userPrincipal =
new GenericPrincipa l(userIdentity, roles);
Context.User = userPrincipal;
}
*************** *************** *************** *************** **

At this point, the roles in the Context.User has a string array containing
"Admin" and "User".

The Redirect goes to my default.aspx page which is:

*************** *************** *************** ***************
void Page_Load(objec t sender, EventArgs e)
{
if(User.Identit y.IsAuthenticat ed )
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is " + User.Identity.N ame;
}
else
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is not authenticated." ;
}
}
*************** *************** *************** ***************

When I go to this page roles in my Context.User is empty.

Why is that?

Thanks,

Tom
Apr 28 '06 #1
3 2039
You need to put the roles into a cookie.
I am playing with GenericPrincipa l classes and am using a sample
program to test it.

The problem is that even though I set the roles (which shows the roles
in the Context.User as being there), when the program goes from the
login page to the next page - the roles in the Context.User is empty.

My Login page is:

*************** *************** *************** *************** *****
private void btnAuthenticate _Click(object sender, System.EventArg s
e)
{
if(txtUserName. Text == "Adam" &&
txtPassword.Tex t == "Dinosaur")
{
string[] roles = {"Admin", "User"};
DoAuthenticate( txtUserName.Tex t, roles);
}
if(Context.User .Identity.IsAut henticated )
{
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
false);
}
}
private void DoAuthenticate (string userName, string[] roles)
{
GenericIdentity userIdentity = new GenericIdentity (userName);
GenericPrincipa l userPrincipal =
new GenericPrincipa l(userIdentity, roles);
Context.User = userPrincipal;
}
*************** *************** *************** *************** **
At this point, the roles in the Context.User has a string array
containing "Admin" and "User".

The Redirect goes to my default.aspx page which is:

*************** *************** *************** ***************
void Page_Load(objec t sender, EventArgs e)
{
if(User.Identit y.IsAuthenticat ed )
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is " +
User.Identity.N ame;
}
else
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is not authenticated." ;
}
}
*************** *************** *************** ***************

When I go to this page roles in my Context.User is empty.

Why is that?

Thanks,

Tom

Apr 28 '06 #2
context is valid for a single request (page render). when you redirect to a
new page, that page gets a new context. you need to store your
authentication info somewhere that the client will send to you on each
request. (say a cookie or url munging)

-- bruce (sqlwork.com)
"tshad" <ts**********@f tsolutions.com> wrote in message
news:eB******** *****@TK2MSFTNG P03.phx.gbl...
I am playing with GenericPrincipa l classes and am using a sample program to
test it.

The problem is that even though I set the roles (which shows the roles in
the Context.User as being there), when the program goes from the login
page to the next page - the roles in the Context.User is empty.

My Login page is:

*************** *************** *************** *************** *****
private void btnAuthenticate _Click(object sender, System.EventArg s e)
{
if(txtUserName. Text == "Adam" &&
txtPassword.Tex t == "Dinosaur")
{
string[] roles = {"Admin", "User"};
DoAuthenticate( txtUserName.Tex t, roles);
}

if(Context.User .Identity.IsAut henticated )
{
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
false);
}
}
private void DoAuthenticate (string userName, string[] roles)
{
GenericIdentity userIdentity = new GenericIdentity (userName);
GenericPrincipa l userPrincipal =
new GenericPrincipa l(userIdentity, roles);
Context.User = userPrincipal;
}
*************** *************** *************** *************** **

At this point, the roles in the Context.User has a string array containing
"Admin" and "User".

The Redirect goes to my default.aspx page which is:

*************** *************** *************** ***************
void Page_Load(objec t sender, EventArgs e)
{
if(User.Identit y.IsAuthenticat ed )
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is " + User.Identity.N ame;
}
else
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is not authenticated." ;
}
}
*************** *************** *************** ***************

When I go to this page roles in my Context.User is empty.

Why is that?

Thanks,

Tom

Apr 28 '06 #3
"Shaun McDonnell" <sh************ *@gmail.com> wrote in message
news:c3******** *************** ****@msnews.mic rosoft.com...
You need to put the roles into a cookie.
That was it.

Thanks,

Tom
I am playing with GenericPrincipa l classes and am using a sample
program to test it.

The problem is that even though I set the roles (which shows the roles
in the Context.User as being there), when the program goes from the
login page to the next page - the roles in the Context.User is empty.

My Login page is:

*************** *************** *************** *************** *****
private void btnAuthenticate _Click(object sender, System.EventArg s
e)
{
if(txtUserName. Text == "Adam" &&
txtPassword.Tex t == "Dinosaur")
{
string[] roles = {"Admin", "User"};
DoAuthenticate( txtUserName.Tex t, roles);
}
if(Context.User .Identity.IsAut henticated )
{
FormsAuthentica tion.RedirectFr omLoginPage(txt UserName.Text,
false);
}
}
private void DoAuthenticate (string userName, string[] roles)
{
GenericIdentity userIdentity = new GenericIdentity (userName);
GenericPrincipa l userPrincipal =
new GenericPrincipa l(userIdentity, roles);
Context.User = userPrincipal;
}
*************** *************** *************** *************** **
At this point, the roles in the Context.User has a string array
containing "Admin" and "User".

The Redirect goes to my default.aspx page which is:

*************** *************** *************** ***************
void Page_Load(objec t sender, EventArgs e)
{
if(User.Identit y.IsAuthenticat ed )
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is " +
User.Identity.N ame;
}
else
{
if(Context.User .IsInRole("Admi n"))
{
lblIdentity.Tex t += " (Admin)";
}
lblIdentity.Tex t = "The current user is not authenticated." ;
}
}
*************** *************** *************** ***************

When I go to this page roles in my Context.User is empty.

Why is that?

Thanks,

Tom


Apr 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3075
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped up, the window does not closes until I click on the window. Below is the code. Hopefully, you can help me out.
0
394
by: okaminer | last post by:
Hi I am currently writing my first ASP.NET application I am trying to get my User Identity in the web page using the following line: CStr(context.User.Identity.Name) The problem is that when I run it in debug mode I get empty string. When I try to run it as browser it works fine Does anyone can know what need to be set in the web config (other then:
3
2371
by: Dmitri Shvetsov | last post by:
Hi, Maybe somebody knows why it's happening? I wrote a C# Windows Application working with the remote database through a DataSet. It works cool from my computer but when I gave this application to my friend who (and only him) has to work with the database tables to edit them he began receiving the following message every time when a new window opens:
0
1562
by: Alireza Haghshenass | last post by:
Dear All, I am facing a problem which I could not solve. I am writing an application which uses a notify icon and a context menu bound to it to show modal dialog forms. When these forms is shown there is no problem but while I am closing any of them which is shown in modal form throw an exception which is described below : Message : External component has thrown an exception. StackTrace : at...
2
1185
by: John Kraft | last post by:
I'm attempting to use the context.user object. In my login code, I add an identity to the context.user. I can use the debugger to watch it stuff the identity into the context.user object, but when I later try to check the context.user.identity.name it contains the empty string (""). Does anyone know why this would be the case? John
3
3350
by: Arjen | last post by:
Hi, I try to get the 'Context.User.Identity.Name' from inside the global.asax in the 'Application_BeginRequest' event. I get this error message: Object reference not set to an instance of an object. You can simple test this with: Response.Write(Context.User.Identity.Name);
2
3967
by: nalbayo | last post by:
what's the difference between HttpContext.Current.User.Identity.Name; and Context.User.Identity.Name; thanks!
0
1295
by: Maxus | last post by:
Hi People, I have written a custom membership and custom roles classes for my application. Then added a asp:Login control to the page. I then hooked into the LoggedIn method of the asp:login control. From there I want to direct my users to diffrent pages depending on the role thier in. When I try to access the Context.User.IsInRole method the whole thing is empty including the actual user itself (Although I appear to be authenticated)....
2
1431
by: =?Utf-8?B?VW1lc2huYXRo?= | last post by:
Hi, My application is running with two web server let say W1 & W2 and load balance controls the request to web servers . One of my application page pop up a new page and there I am using Context.User prpoerty to get current user informtaion and convert into my customer class which lot of customer information . This works fine in Developement environment and when it moves to production some times the customer class is not getting...
0
9506
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9317
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10090
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9758
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8759
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6580
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2719
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.