RE: Membership Provider Woes
- From: Chris Cap <ccapriccio@xxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Dec 2006 09:45:00 -0800
Thanks Steven,
I have a few questions. The FormsIdentity class you reference, is that a
custom class I have to write that implements IIdentity or is it just
available.
Second, how do I actually store the custom information? From the looks of
it, I pass infomration into the constructor of the FormsAuthenticationTicket,
but which parameter does it? Is it the "1" that you pass in?
How can I easily access this information later? It looks like once you pass
the information into the cookie, you can pull it out using
identity.Ticket.UserData. However, isn't this just implementing a custom
IIdentity...which is kind of the asp.net 1.1 way?
Doens't the membership provider set a forms auth cookie for me
automatically? Will setting the cookie manually cause a problem?
Is there any way to intercept the data from the Membership provider? As it
stands, the membership provider will go to the database to authenticate the
user, then I will have to go to the database manually again just to get their
user information. I tried finding an event that would return the data as
with an objectdatasoure, but I haven't found any. Is there any way to avoid
this extra call that the Membership provider is doing anyway.
It's a little disappointing that I have to do so much hacking to get
something so simple to work. I would have thought .net 2.0 would have
covered this a little better.
"Steven Cheng[MSFT]" wrote:
Hello Chris,.
From your description, you are using the Membership/Role providers to
perform forms authentication in your ASP.NET web application. You like the
built-in membership/role provider feature and the login controls, however,
you also want to add additional custom data(specifci to each user) into the
forms authentication cookie (without querying database in each request),
correct?
Based on my experience, since ASP.NET 2.0's membershp/role provider and
service model has been well encapsulated, it is not quite convenient to
modify it or develop our own model to replace them. And what you need here
is just cache some custom data into forms auth ticket and used in other
pages later, I think you can simply add them into the
FormsAuthenticationTicket(created manually) and then access it later
through the FormsIdentity.Ticket property. e.g.
========in page which want to access the custom data in authenticatino
ticket=======
protected void Page_Load(object sender, EventArgs e)
{
//you can even define a helper function for extract custom data from
ticket.UserData string
Response.Write("<br/>CurrentIdentity: " + Context.User.Identity);
FormsIdentity identity = Context.User.Identity as FormsIdentity;
Response.Write("<br/>Ticket.UserData: " + identity.Ticket.UserData);
}
===============
the forms authentication module will help retrieve teh userdata from
ticket(from cookie) and store it in the FormsIdentity(in the
HttpContext.Current.User.Identity). Also, in your login page, you need to
manually create the FormsAuthentication ticket so that you can add
additional data into "UserData" property of the ticket. e.g.
=========in our custom logging page's code============
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
Login1.UserName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
Login1.RememberMeSet,
"some custom data want to store in ticket....", // User-data, in
this case the roles
FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
hash);
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
============================
Hope this helps for your scenario.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
- Follow-Ups:
- RE: Membership Provider Woes
- From: Steven Cheng[MSFT]
- RE: Membership Provider Woes
- References:
- RE: Membership Provider Woes
- From: Steven Cheng[MSFT]
- RE: Membership Provider Woes
- Prev by Date: Re: doubt regarding load and init
- Next by Date: Re: SQLDataSource and asp.net data display: iterating only the middle of the collection?
- Previous by thread: RE: Membership Provider Woes
- Next by thread: RE: Membership Provider Woes
- Index(es):
Relevant Pages
|