Results 1 to 10 of 10

Thread: System.ArgumentException error

  1. #1
    keroed1 Guest

    Default System.ArgumentException error

    can anyone help me with this problem i having when some persons try to view my website they get the following error message

    Exception Details: System.ArgumentException: Invalid value for 'encryptedTicket' parameter

    source error

    httpcook = Context.Request.Cookies["authCookie"];
    formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value);

    genIdentity = new GenericIdentity(formsAuthTicket.Name);

  2. #2
    Join Date
    Jul 2006
    Posts
    239
    Rep Power
    0

    Default

    I think that your issue comes from the first line. You're expecting a cookie to be there when there might not be one. Also, remove context, request will use the current context by default.

    Try This:


    Code:
        if (Request.Cookies["authCookie"] != null) { 
            httpcook = Request.Cookies["authCookie"]; 
            formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value); 
            
            genIdentity = new GenericIdentity(formsAuthTicket.Name); 
        }
    Last edited by redbwoy; Oct 3, 2007 at 04:20 PM.

  3. #3
    keroed1 Guest

    Default

    Quote Originally Posted by redbwoy View Post
    I think that your issue comes from the first line. You're expecting a cookie to be there when there might not be one. Also, remove context, request will use the current context by default.

    Try This:



    if ((Request.Cookies("authCookie") != null)) {
    httpcook = Request.Cookies("authCookie");
    formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value);

    genIdentity = new GenericIdentity(formsAuthTicket.Name);
    }
    oh ok cool when i get back into office i try what you said. i will post the result what should i do if it is null?

  4. #4
    Join Date
    Jul 2006
    Posts
    239
    Rep Power
    0

    Default

    Quote Originally Posted by keroed1 View Post
    oh ok cool when i get back into office i try what you said. i will post the result what should i do if it is null?
    If its null, then you need to create the cookie so the next time the user comes back they will have the cookie you're looking for.

  5. #5
    keroed1 Guest

    Default

    Quote Originally Posted by redbwoy View Post
    If its null, then you need to create the cookie so the next time the user comes back they will have the cookie you're looking for.
    this is what i did
    Code:
     if ((Request.Cookies["authCookie"] != null))
            {
                httpcook = Request.Cookies["authCookie"];
                formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value);
    
                genIdentity = new GenericIdentity(formsAuthTicket.Name);
                
                roles = formsAuthTicket.UserData.Split(separators); 
                genPrincipal = new GenericPrincipal(genIdentity, roles);
                HttpContext.Current.User = genPrincipal;
            }
    its still not working but but the program enters the if statement because it say the exception occurred at formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value); so it seems that it is unable to decrypt but next thing i should say anyone who is a member of IM[our it department] it works perfectly is when a normal user tries to view the page that it throws that error

  6. #6
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    Either httpcook.Value is a null reference (Nothing in Visual Basic).

    - or -

    httpcook.Value is an empty string ("").

    - or -

    httpcook.Value is of an invalid format.

    http://msdn2.microsoft.com/en-us/lib...n.decrypt.aspx

    Try testing against the value of the Parameter before passing it into the Decrypt function
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  7. #7
    Join Date
    Jul 2006
    Posts
    239
    Rep Power
    0

    Default

    Yeah, "recursion" is right. It could be that the cookie is there on their machine but it has no value or the wrong value in it. It would be best if you could put a break point in your code and step through and see what the values are.

    i would also put a conditional statement in it. Something like this:

    Code:
    if ((Request.Cookies["authCookie"] != null))
            {
                httpcook = Request.Cookies["authCookie"];
                
                if(!String.IsNullOrEmpty(httpcook.Value)){
     
                formsAuthTicket = FormsAuthentication.Decrypt(httpcook.Value);
    
                genIdentity = new GenericIdentity(formsAuthTicket.Name);
                
                roles = formsAuthTicket.UserData.Split(separators); 
                genPrincipal = new GenericPrincipal(genIdentity, roles);
                HttpContext.Current.User = genPrincipal;
    
                }
            }

  8. #8
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    Quote Originally Posted by redbwoy View Post
    Yeah, "recursion" is right. It could be that the cookie is there on their machine but it has no value or the wrong value in it. It would be best if you could put a break point in your code and step through and see what the values are.
    He says it works for machines in his department so debugging might be a bit difficult for the testing he requires. He might have to set up some Traces or if possible connect the debugger to the process on the remote machine in the other department.
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  9. #9
    keroed1 Guest

    Default

    Quote Originally Posted by recursion View Post
    He says it works for machines in his department so debugging might be a bit difficult for the testing he requires. He might have to set up some Traces or if possible connect the debugger to the process on the remote machine in the other department.
    yes it works for me fine as a mater of fact everyone my it department it works fine is jus other normal users that it gives that error i skipped the entire getting roles and ecyrpting the cookie and jus created a cookie that gets the user name and then checks for the roles thats sloopy in the sense that thats not how its normally done i think when i get to work will post what exactly i did

  10. #10
    keroed1 Guest

    Default

    this is what i did

    Code:
     protected void WindowsAuthentication_OnAuthenticate(Object sender, WindowsAuthenticationEventArgs e)
        {
            FormsAuthenticationTicket formsAuthTicket;
            HttpCookie httpcook;
            HttpCookie cookieName;
            String encryptedTicket;
            String strUserIdentity;
            DBconn getUser_Roles = new DBconn();
    
            strUserIdentity = e.Identity.Name;
             
            string[] temp = strUserIdentity.Split('\\');
            strUserIdentity = temp[1];
    
            cookieName = new HttpCookie("cookieName", strUserIdentity);
                   
            Response.Cookies.Add(cookieName);
           
        }
    
        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
        {
    
            // Fires upon attempting to authenticate the user
            FormsAuthenticationTicket formsAuthTicket;
            HttpCookie httpcook;
            GenericIdentity genIdentity;
            String[] roles = new string[5];
            String rolesString;
            DBconn getUser_Roles = new DBconn();
                
            char[] separators = { '|' };
            GenericPrincipal genPrincipal;
                 
            string user = Request.Cookies["cookieName"].Value;
            genIdentity = new GenericIdentity(user);
    
            rolesString = getUser_Roles.GetUserRoles(user);
            if (rolesString != null)
            {
                roles = rolesString.Split(separators);
            }
            else
            {
                rolesString ="normal";
                roles = rolesString.Split(separators);
            }
            genPrincipal = new GenericPrincipal(genIdentity, roles);
            HttpContext.Current.User = genPrincipal;
           
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •