Re: IsInRole problem

From: yogaboy (yogaboy.1ym8y1_at_mail.codecomments.com)
Date: 11/16/05


Date: Wed, 16 Nov 2005 08:55:08 -0600


I've been having the same problem. I used the same code to output
(qouted below), and I hard-coded in the string "Admin,User" when
setting up the ticket.

What I've noticed is that the string doesn't get written to UserData in
the cookie. So this (I think) is where the problem lies...

Code:
--------------------
  
  string ROLE = "Admin,User"
  
  if (authentic)
  {
  FormsAuthentication.Initialize();
  
  FormsAuthenticationTicket ticket = new
  FormsAuthenticationTicket(1, userid, DateTime.Now, DateTime.Now.AddMinutes(30), true, ROLE , FormsAuthentication.FormsCookiePath);
  
--------------------
 

when setting up the ticket it's not taking the ROLE properly, so you
can't get the roles back out of the cookie.

Colin Peters wrote:
> *
> So I thought I'd investigate myself. I found by outputing to the page
> in
> the prod environment, that I get the right roles via:
>
> FormsIdentity id =
> (FormsIdentity)HttpContext.Current.User.Identity;
> FormsAuthenticationTicket ticket = id.Ticket;
>
> // Get the stored user-data, in this case, our roles
> string userData = ticket.UserData;
> string[] roles = userData.Split(',');
>
> so I know the roles are stored int he cookie OK.
>
> *

--
yogaboy
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
 


Relevant Pages

  • Re: problem with slidingExpiration
    ... DateTime dt= DateTime.Now; ... //cripto l'authentication ticket ... string cookiestr = FormsAuthentication.Encrypt; ... //aggiungo il cookie ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • FormsAuthentication und schlaflose Nächte
    ... FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( ... string sEncTicket = FormsAuthentication.Encrypt; ... Die Rolle im Ticket aufzubewahren scheint mir das Naheliegenste zu sein. ... Auf der Logon Seite finde ich ...
    (microsoft.public.de.german.entwickler.dotnet.asp)
  • RE: Help with form code - If / then statement
    ... Dim lngField_Ticket_Number As Long, strCriteria As String ... MsgBox "That ticket number already exists in the database. ... I'm want to be able to either enter in a string "SHOP TIME" to collect ...
    (microsoft.public.access.formscoding)
  • Cannot retrieve UserData in Forms Authentication
    ... and am getting user data back from the cookie. ... I assume your setting the ticket in a login page. ... >Dim authTicket As New FormsAuthenticationTicket(1, ... >Dim encryptedTicket As String = ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: forms auth, authenticate against already encrypted password?
    ... why don't you provide a "login.asmx" web service with no auth required - which returns the encrypted ticket as a string - like: ... HttpWebRequest req = HttpWebRequest.Createas HttpWebRequest; ...
    (microsoft.public.dotnet.framework.aspnet.security)