473,609 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing Role And User Id in UserData of FormAuthenticat ion

hello,

i have been scouring the groups for the best possible solution to this
problem, but can't seem to find my exact scenario, so hopefully someone
can get me back on the right path. my situation is the following:

i have a asp.net app that uses formsauthentica tion, and in the UserData
field we store the role value of what the user is (ie admin, user,
etc.). i want to also store the user id in this UserData field so i
have added that and separated it by a comma, so the value would look
something like "Admin,123" . so on the Application_Aut henticateReques t
event in global.asax.vb i can easily split the values on the comma and
then have the roles which are used in:

HttpContext.Cur rent.User = New GenericPrincipa l(id, asRoles)

to verify whether they have access to certain directories or whatnot.
but within this GenericPrincipa l there doesn't seem to be a place to
store this User Id value and have it readily available from each page.
i know you can do something like HttpContext.Cur rent.User.Ident ity.Name
and that will give you the name value that you stored in the
formsauthentica tion ticket, but there still isn't a way to get the user
id. i tried setting a session variable in the
Application_Aut henticateReques t event to store the user id, but kept
getting an error; my thinking was that this way the authentication and
session would still be in sync because every time the user
authenticated, the session variable would be set (and i wouldn't be
using the session variable on pages that did not require
authentication) . i have also seen where the id is appended to the Name
in the ticket, and then split out, but that doesn't seem very .net like
to me.

so i guess my question is what am i missing? most examples i have seen
just store the "roles" in the user data field, and not multiple types
of data like user id, first name, last name, etc.

thanks to any and all who respond,
jamie

Nov 19 '05 #1
4 1946
Hi Jamie:

After you have assigned the GenericPrincipa l to the
HttpContext.Cur rent.User, you can always retrieve the User ID back from the
FormsAuthentica tionTicket in the Context.User.Id entity:

CType(CType(CTy pe(Context.User .Identity,
System.Security .Principal.IIde ntity),
System.Web.Secu rity.FormsIdent ity).Ticket,
System.Web.Secu rity.FormsAuthe nticationTicket ).UserData

---
www.societopia.net
"Jamie Pollard" wrote:
hello,

i have been scouring the groups for the best possible solution to this
problem, but can't seem to find my exact scenario, so hopefully someone
can get me back on the right path. my situation is the following:

i have a asp.net app that uses formsauthentica tion, and in the UserData
field we store the role value of what the user is (ie admin, user,
etc.). i want to also store the user id in this UserData field so i
have added that and separated it by a comma, so the value would look
something like "Admin,123" . so on the Application_Aut henticateReques t
event in global.asax.vb i can easily split the values on the comma and
then have the roles which are used in:

HttpContext.Cur rent.User = New GenericPrincipa l(id, asRoles)

to verify whether they have access to certain directories or whatnot.
but within this GenericPrincipa l there doesn't seem to be a place to
store this User Id value and have it readily available from each page.
i know you can do something like HttpContext.Cur rent.User.Ident ity.Name
and that will give you the name value that you stored in the
formsauthentica tion ticket, but there still isn't a way to get the user
id. i tried setting a session variable in the
Application_Aut henticateReques t event to store the user id, but kept
getting an error; my thinking was that this way the authentication and
session would still be in sync because every time the user
authenticated, the session variable would be set (and i wouldn't be
using the session variable on pages that did not require
authentication) . i have also seen where the id is appended to the Name
in the ticket, and then split out, but that doesn't seem very .net like
to me.

so i guess my question is what am i missing? most examples i have seen
just store the "roles" in the user data field, and not multiple types
of data like user id, first name, last name, etc.

thanks to any and all who respond,
jamie

Nov 19 '05 #2
wow, thanks a bunch, that is exactly what i needed. i'm kinda confused
by that statement though. could you please explain how that is working?

thanks,
jamie

Nov 19 '05 #3
"Jamie Pollard" wrote:
wow, thanks a bunch, that is exactly what i needed. i'm kinda confused
by that statement though. could you please explain how that is working?

thanks,
jamie


You are welcome. In your original code you created a GenericPrincipl e
object using a FormsAuthentica tionTicket. Therefore all you needed was to
retrieve the UserData property of the FormsAuthentica tionTicket. (The
UserData has the User ID value that you were looking for)

---
www.societopia.net

Nov 19 '05 #4
yeah, i realized that part. i guess i just figured that there wasn't an
easy way to access that data without creating the ticket again and
extracting the data like in the Application_Aut henticateReques t Sub.
but this does exactly what i want. i guess my main questions is with
all the ctypes and everything? i mean i know what ctype does, just
kinda don't know how it's actually working.

thanks,
jamie

Nov 19 '05 #5

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

Similar topics

4
9424
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
2
3039
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some content based on the user's role. I wrote this to do it: if (HttpContext.Current.User.Identity.IsAuthenticated) { plLoggedIn.Visible = true;
0
1507
by: Sean Patterson | last post by:
Hey all, I've followed the examples online on how to use Forms Authentication to create a ticket, assign it a role, and then intercept it in the Global.asax file to make sure it gets sucked in to the IPrincipal. This has worked on some other apps, but my code isn't working in my new one for some reason. Here's my CreateCredentials code: Private Sub CreateCredentials(ByVal UserID As String, ByVal UserRole As String)
5
1925
by: Archer | last post by:
I was making a role-based authentication but it does't login with correct password. the HttpContext.Current.User recieved in Global.asax is always null. Request.IsAuthenticated is always false. in the cs files, i write the code below protected void SubmitBtn_Click(Object sender, EventArgs e) {
0
837
by: Colin Peters | last post by:
Hi, I have the following problem: I've implemented role based security and it worked fine on both my local dev machine and my remote shared host. Now it only works on my dev machine. My shared host had some unidentified problems but I'm not sure they are related so I can't really ask them to change something. So I thought I'd investigate myself. I found by outputing to the page in
1
1143
by: Vivian | last post by:
hi, I'm new to .aspx and want to ask a question about FormAuthentication. I've created a login page and a default page, it works well in the login page and can redirect to the default page. The problem is I want to get the login name in the default page, what function should I use? Thanks in advance. Vivian
2
1429
by: Anthony Smith | last post by:
I have read the message boards in this group and others. I still have not been able to pull my obect out of a session and use it. Here is how I store it in a session: <? //Include the UserClass & RoleClass so that we can create a user object. require_once("UserClass.php"); require_once("RoleClass.php");
2
23790
by: Anthony Smith | last post by:
I have read the message boards in this group and others. I still have not been able to pull my obect out of a session and use it. Here is how I store it in a session: <? //Include the UserClass & RoleClass so that we can create a user object. require_once("UserClass.php"); require_once("RoleClass.php");
3
1267
by: nimmyjo | last post by:
Hi friends, I have done role based authentication, now has two roles ,Admin and User. using location tag in web.cofig. FormAuthentication.DirectfromLoginpage is working fine. But I am not able to redirect to Admin page after login as Admin using if(User.IsInRole("Admin")==true) { Response.Redirect("Admin.aspx");
0
8145
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
8095
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
8556
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7030
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...
1
6068
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5526
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();...
1
2541
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1690
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1407
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.