473,406 Members | 2,705 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,406 software developers and data experts.

Custom IIdentity class - how to set it?

I have created my own IIdentity class (actually inherited from
GenericIdentity) to contain lots of extra useful information to be passed
around with the user's basic information.
The class compiles fine, no problems there.

My problem is that i'm not sure where to actually set this to be part of the
HttpContext. I know that the IIdentity stuff is part of a principal (which
in my case will be a GenericPrinciple i suppose since i'm using forms
authentication). So i figure it needs to be whenever the HttpContext.User
object is set.

What event is raised that i need to handle to be able to do this? I'm going
to be controlling all of the authentication using custom forms
authentication.

Is there a good tutorial about this type of stuff (the 'flow' of the
authentication information) that someone could point me to?

Thanks in advance,

Tim
Nov 18 '05 #1
6 4342
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
I have created my own IIdentity class (actually inherited from
GenericIdentity) to contain lots of extra useful information to be passed
around with the user's basic information.
The class compiles fine, no problems there.

My problem is that i'm not sure where to actually set this to be part of the HttpContext. I know that the IIdentity stuff is part of a principal (which
in my case will be a GenericPrinciple i suppose since i'm using forms
authentication). So i figure it needs to be whenever the HttpContext.User
object is set.

What event is raised that i need to handle to be able to do this? I'm going to be controlling all of the authentication using custom forms
authentication.


You need to do this sort of thing in the Application_AuthenticateRequest
event in global.asax.

Be sure to check Request.IsAuthenticated, first, though!
--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #2
i've been looking into that...
am i correct then in thinking that this event will be raised multiple times
per page request, and i'll handle it when they've been authenticated and
fill in the User information then? So then the user information would be
recreated (accessed from a db, or whatever) everytime a page loads?
Is there a better way to do that?
Or am i just totally missing something?

"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
I have created my own IIdentity class (actually inherited from
GenericIdentity) to contain lots of extra useful information to be passed around with the user's basic information.
The class compiles fine, no problems there.

My problem is that i'm not sure where to actually set this to be part of

the
HttpContext. I know that the IIdentity stuff is part of a principal (which in my case will be a GenericPrinciple i suppose since i'm using forms
authentication). So i figure it needs to be whenever the HttpContext.User object is set.

What event is raised that i need to handle to be able to do this? I'm

going
to be controlling all of the authentication using custom forms
authentication.


You need to do this sort of thing in the Application_AuthenticateRequest
event in global.asax.

Be sure to check Request.IsAuthenticated, first, though!
--
John Saunders
John.Saunders at SurfControl.com

Nov 18 '05 #3
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
i've been looking into that...
am i correct then in thinking that this event will be raised multiple times per page request, and i'll handle it when they've been authenticated and
fill in the User information then? So then the user information would be
recreated (accessed from a db, or whatever) everytime a page loads?
Is there a better way to do that?
Or am i just totally missing something?
No. The event will only be raised once per page.

And, yes, it does have to be recreated every page load - so it would be a
good idea to avoid a database hit on each load. Many people do this by
setting the UserData field of the FormsAuthenticationTicket on their login
page, then reading the UserData during Application_AuthenticateRequest. The
idea would be to use it to hold information you'd otherwise have to go to
the database for, but which you don't mind having a bit out of date (it will
be from the time of login, if you never refresh it).

--
John Saunders
John.Saunders at SurfControl.com

"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
I have created my own IIdentity class (actually inherited from
GenericIdentity) to contain lots of extra useful information to be passed around with the user's basic information.
The class compiles fine, no problems there.

My problem is that i'm not sure where to actually set this to be part
of
the
HttpContext. I know that the IIdentity stuff is part of a principal

(which in my case will be a GenericPrinciple i suppose since i'm using forms
authentication). So i figure it needs to be whenever the HttpContext.User object is set.

What event is raised that i need to handle to be able to do this? I'm

going
to be controlling all of the authentication using custom forms
authentication.


You need to do this sort of thing in the Application_AuthenticateRequest
event in global.asax.

Be sure to check Request.IsAuthenticated, first, though!
--
John Saunders
John.Saunders at SurfControl.com


Nov 18 '05 #4
Thanks for the help John. Much appreciated.

Tim

"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:en**************@TK2MSFTNGP10.phx.gbl...
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
i've been looking into that...
am i correct then in thinking that this event will be raised multiple times
per page request, and i'll handle it when they've been authenticated and
fill in the User information then? So then the user information would be
recreated (accessed from a db, or whatever) everytime a page loads?
Is there a better way to do that?
Or am i just totally missing something?


No. The event will only be raised once per page.

And, yes, it does have to be recreated every page load - so it would be a
good idea to avoid a database hit on each load. Many people do this by
setting the UserData field of the FormsAuthenticationTicket on their login
page, then reading the UserData during Application_AuthenticateRequest.

The idea would be to use it to hold information you'd otherwise have to go to
the database for, but which you don't mind having a bit out of date (it will be from the time of login, if you never refresh it).

--
John Saunders
John.Saunders at SurfControl.com

"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
"Tim Mulholland" <Ti***********@nospamaddress.com> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
> I have created my own IIdentity class (actually inherited from
> GenericIdentity) to contain lots of extra useful information to be passed
> around with the user's basic information.
> The class compiles fine, no problems there.
>
> My problem is that i'm not sure where to actually set this to be part of
the
> HttpContext. I know that the IIdentity stuff is part of a principal

(which
> in my case will be a GenericPrinciple i suppose since i'm using

forms > authentication). So i figure it needs to be whenever the

HttpContext.User
> object is set.
>
> What event is raised that i need to handle to be able to do this? I'm going
> to be controlling all of the authentication using custom forms
> authentication.

You need to do this sort of thing in the Application_AuthenticateRequest event in global.asax.

Be sure to check Request.IsAuthenticated, first, though!
--
John Saunders
John.Saunders at SurfControl.com



Nov 18 '05 #5
Hi Tim,

Thanks for posting in the community!
From your description, you're using the FormsAuthentication in ASP.NET and
you're wondering the time when to set the customized principle object(with
the proper roles) to the HttpContext.Current.User, yes?

Based on my expericence, generally , in formsauthentication, since the
roles must be retrieved and set manually via code, so we can put those code
in the Application_AuthenticateRequest event of the global
object(global.asax/global.asax.cs). At that time ,the request hasn't been
processed , we can first retireved all the proper roles of the current user
from our datasource and create a principle objectd and set it to the
HttpContext.Current.User, for example:
---------------------
Sub Application_AuthenticateRequest....
'f?rst hentes roller for brugeren ud i
'array'et roleListArray... og derefter:
HttpContext.Current.User =
New GenericPrincipal(User.Identity, roleListArray)
end sub
---------------------

And here are two tech articles discussing detailedly on this:

#HOW TO: Implement Role-Based Security with Forms-Based Authentication in
Your ASP.NET Application by Using Visual C# .NET
http://support.microsoft.com/?id=311495

#Using Forms Authentication in ASP.NET
http://www.xoc.net/works/tips/forms-authentication.asp

Please check out the above things to see whether they answer your question.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #6
Hi Tim,
Have you had a chance to check out the suggestions in my last reply or have
you got any ideas on this issue? If you have anything unclear or need any
further help, please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7

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

Similar topics

0
by: andrew lowe | last post by:
Hi We have windows application and have created our own custom principle & identity objects that implement IPrinciple and IIdentity. When a user logs into our system we set the threads principle...
1
by: Michael Shutt | last post by:
We have an existing ISAPI filter that performs authentication for all pages on our web site, including pages we are now writing for ASP.NET. The filter is pretty basic, receiving the user name and...
6
by: Craig Buchanan | last post by:
I have an object, named SiteIdentity, that implements IIdentity. I have added additional properties to this class, Email for instance. I am using forms authentication. In the code behind class...
2
by: Mark | last post by:
We'd like to capture the windows account of the current web user. In our code-behinds, this is cake using: System.Security.Principal.IIdentity ii = User.Identity; Reponse.Write("User: " +...
3
by: David B. Bitton | last post by:
For some odd reason, despite the fact that I assign my own custom IPrincipal to the HttpContext.User property in an HttpApplication.AuthenticateRequest event handler inside of an IHttpModule,...
2
by: lucd | last post by:
Hello, I am currently playing with form authentication & role based security on a web application. As seen in the starter kit Time tracker, I setup a custom identity class (CustomPrincipal)...
0
by: Mythran | last post by:
We have a class that Implements IPrincipal (System.Security.Principal.IPrincipal). We have a business logic class library assembly that checks the Principal object for role information to see if...
2
by: Spondishy | last post by:
Hi, I'm attempting to extend IIdentity to enable me to have more information on the user (email etc) and store it in a cookie. I assume I am extending the correct object (but if not shout up). ...
1
by: Jakob Lithner | last post by:
When I started a new ASP project I was eager to use the login facilities offered in Framework 2.0/VS 2005. I wanted: - A custom principal that could hold my integer UserID from the database -...
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...
1
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...
0
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...
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
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...
0
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...
0
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,...

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.