RE: Membership Provider Woes



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.

.



Relevant Pages

  • Re: * * * C# Application and Database Security Model * * *
    ... I've noticded that your main concern here is to provide security ... If you're going to do authentication and authorization against windows ... authenticate user against custom security account database and authroize ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Error Writing to Event Log
    ... me what authentication mode you are using in you Asp.net project? ... modify the DACL setting of eventlog in registry with SDDL format. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.general)
  • Re: Restrict size of Custom Task Pane
    ... restrict the size of a custom task pane when users stretch it. ... Microsoft Online Community Support ... For MSDN subscribers whose posts are left unanswered, ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Calling SQL Native Web Service failed as unauthorized
    ... I understand that when you try to Add web reference to a sql http web ... right for kerberbose authentication. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.sqlserver.xml)
  • RE: Securing a single aspx page
    ... forms authentication by default will allow everyone access ... authorization setting: ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)