I am playing with GenericPrincipal 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.EventArgs e)
{
if(txtUserName.Text == "Adam" &&
txtPassword.Text == "Dinosaur")
{
string[] roles = {"Admin", "User"};
DoAuthenticate(txtUserName.Text, roles);
}
if(Context.User.Identity.IsAuthenticated )
{
FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text,
false);
}
}
private void DoAuthenticate (string userName, string[] roles)
{
GenericIdentity userIdentity = new GenericIdentity(userName);
GenericPrincipal userPrincipal =
new GenericPrincipal(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(object sender, EventArgs e)
{
if(User.Identity.IsAuthenticated )
{
if(Context.User.IsInRole("Admin"))
{
lblIdentity.Text += " (Admin)";
}
lblIdentity.Text = "The current user is " + User.Identity.Name;
}
else
{
if(Context.User.IsInRole("Admin"))
{
lblIdentity.Text += " (Admin)";
}
lblIdentity.Text = "The current user is not authenticated.";
}
}
************************************************** **********
When I go to this page roles in my Context.User is empty.
Why is that?
Thanks,
Tom 3 2011
You need to put the roles into a cookie. I am playing with GenericPrincipal 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.EventArgs e) { if(txtUserName.Text == "Adam" && txtPassword.Text == "Dinosaur") { string[] roles = {"Admin", "User"}; DoAuthenticate(txtUserName.Text, roles); } if(Context.User.Identity.IsAuthenticated ) { FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, false); } } private void DoAuthenticate (string userName, string[] roles) { GenericIdentity userIdentity = new GenericIdentity(userName); GenericPrincipal userPrincipal = new GenericPrincipal(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(object sender, EventArgs e) { if(User.Identity.IsAuthenticated ) { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is " + User.Identity.Name; } else { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is not authenticated."; } } ************************************************** **********
When I go to this page roles in my Context.User is empty.
Why is that?
Thanks,
Tom
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**********@ftsolutions.com> wrote in message
news:eB*************@TK2MSFTNGP03.phx.gbl... I am playing with GenericPrincipal 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.EventArgs e) { if(txtUserName.Text == "Adam" && txtPassword.Text == "Dinosaur") { string[] roles = {"Admin", "User"}; DoAuthenticate(txtUserName.Text, roles); }
if(Context.User.Identity.IsAuthenticated ) { FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, false); } } private void DoAuthenticate (string userName, string[] roles) { GenericIdentity userIdentity = new GenericIdentity(userName); GenericPrincipal userPrincipal = new GenericPrincipal(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(object sender, EventArgs e) { if(User.Identity.IsAuthenticated ) { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is " + User.Identity.Name; } else { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is not authenticated."; } } ************************************************** **********
When I go to this page roles in my Context.User is empty.
Why is that?
Thanks,
Tom
"Shaun McDonnell" <sh*************@gmail.com> wrote in message
news:c3***************************@msnews.microsof t.com... You need to put the roles into a cookie.
That was it.
Thanks,
Tom I am playing with GenericPrincipal 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.EventArgs e) { if(txtUserName.Text == "Adam" && txtPassword.Text == "Dinosaur") { string[] roles = {"Admin", "User"}; DoAuthenticate(txtUserName.Text, roles); } if(Context.User.Identity.IsAuthenticated ) { FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, false); } } private void DoAuthenticate (string userName, string[] roles) { GenericIdentity userIdentity = new GenericIdentity(userName); GenericPrincipal userPrincipal = new GenericPrincipal(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(object sender, EventArgs e) { if(User.Identity.IsAuthenticated ) { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is " + User.Identity.Name; } else { if(Context.User.IsInRole("Admin")) { lblIdentity.Text += " (Admin)"; } lblIdentity.Text = "The current user is not authenticated."; } } ************************************************** **********
When I go to this page roles in my Context.User is empty.
Why is that?
Thanks,
Tom
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nalbayo |
last post by:
what's the difference between
HttpContext.Current.User.Identity.Name;
and
Context.User.Identity.Name;
thanks!
|
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...
|
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...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |