473,388 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Concatenate columns value returns by datareader

50
I manage to store the additional use data (username, fullname, rolecode) in FormAuthenticationTicket. However ,
the user has more than one role , he can be admin, poweruser , executive ,etc... can anyone please tell me how can i concatenate the rodecode return by datareader if it returns more than 1 value? so that i can put it as a string in userdatastring of the authentication ticket?

eg:
If datareader returns:

UserName FullName RoleCode
amy33 amy watson ADMIN
amy33 amy watson POWERUSER
amy33 amy watson EXEC

how can i can i store all this 3 RoleCode in userdatastring?
Thank you !


Expand|Select|Wrap|Line Numbers
  1. drDataReader = cmd.ExecuteReader()
  2. While drDataReader.Read()
  3.  
  4. strFullName = drDataReader("FullName").ToString
  5. strUserName = drDataReader("UserName").ToString
  6. strRoleCode = drDataReader("RoleCode").ToString
  7. userDataString = String.Concat(strFullName, "|", strUserName, "|", strRoleCode)
  8.  
  9. Dim authCookie As HttpCookie = FormsAuthentication.GetAuthCookie(txtUserName.Text, chkPersistCookie.Checked)
  10.  
  11. Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(authCookie.Value)
  12.  
  13. Dim newTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString)
  14.  
Aug 16 '11 #1
4 2849
Frinavale
9,735 Expert Mod 8TB
You shouldn't be storing the user's roles in the Forms Authentication ticket.

When the request to the server is made for your website, the ASP.NET Forms Authentication feature will check if there is a valid Forms Authentication cookie (ticket). If so, the authentication feature creates a Token that represents the user. This token is created based on information retrieved from your database. The token is then set in the HttpContext.User property which is accessible through out your application.

You should be using the User property to check for roles etc.
You should Not be storing this information in the cookie.

-Frinny
Aug 16 '11 #2
beemomo
50
Thanks for your reply , Frinny.

This is the first time I create the login page using form authentication. Sorry for my noobness.

I've been struggling for several to find the answer on how can i store the user's additional data. Thanks for your advise , but that would be great if you can explain how can I store user data using HttpContext.User

Public Property User As IPrincipal
Get
Set

Hmm, i have a bunch of questions here:
What should i put in the Get and Set section so that it knows which user i refer to? Do need to do any query to refer to that user with the ticket? Hope that u can explain by providing some codes example or information? Many thanks again, Frinny.
Aug 17 '11 #3
Frinavale
9,735 Expert Mod 8TB
It sounds like you're interested in implementing your own Principal and Identity Objects.

Essentially the Principal object contains all of the security information...like the user's permissions, roles etc.

The Principal object has an Identity property.
The Identity class contains the user's personal information...like the user's name, birth date(if you want)... etc

Here is a walkthrough about implementing custom Authentication and Authorization that I think you'll find really helpful :)

-Frinny

Edit: PS if you still have problems after working through the walk through I'll do my best to help you solve them
Aug 17 '11 #4
beemomo
50
Thanks again Frinavale for your reply. Sorry for my late reply because I have been away from my workstation since last weekend.

I have tried the walk through, and will try to implement this into my project.

I really appreciate your advise and reply. This is a new and very useful peace of knowledge for me to learn and explore.

Cheers,
beemomo
Aug 22 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jim Carlock | last post by:
Does a SELECT element (listbox) need to be inside a FORM element? The code I'm playing with: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
0
by: anaik100 | last post by:
i just want to write a SQL query to concantenate two columns to form a part of where clause ex query SELECT * FROM tab1 a,tab2 b WHERE a.ID='b.col1+b.col2' i am trying to put it in DB2..but...
1
by: Goomba | last post by:
i am trying to put a space between title_the and title ONLY if title_the is not null. below is what i have, but it is returning the empty space regardless of whether the value is null or not. ...
4
by: Keith Patrick | last post by:
I'm trying to parse some XML via IXPathNavigable, handling elements, text, and attributes with the same code but without having a switch (node.NodeType). However, if I look at a parent element in...
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
4
by: Varangian | last post by:
Hello, I know that the kind of question below has been asked several times....however I need a clear answer in my specific situation. I have 2 methods. One returns an SqlDataReader and the...
7
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to create a generic class which will take a command string and I can issue statement like this: Dim rdrCustomers As New Generic_Reader("select * from customers") However, I have not...
2
by: ratcateme | last post by:
I have this script to validate my reregistration form then send it to a AJAX handler to create the new user my problem is that when getting the value of the username and password filed it returns...
5
by: axapta | last post by:
Hi Group, How can I overcome the issue of null values in a datareader. I keep getting the dbnull error when I try to assign a null value to a text box. TIA
3
Soniad
by: Soniad | last post by:
Hello, In stored procedure, i am using query that fetches 2 columns record but single row. i have used cursor to fetch single record. is there any way to fetch the record and put it in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
0
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,...
0
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...
0
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...
0
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...

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.