SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member das.ujjwal's Avatar
    Join Date
    Jun 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Form Authentication can be done from page.

    Expert,

    In one application, they are using framework dll in project. The framework project is handling the global.asax and Form authentication.

    Any how i am not sure that sometimes form authentication is not working.

    so, I use my code in web project is as follows:

    Code:
    System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(50), false, userName);
                string hashCookies = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, hashCookies); // Hashed ticket
                // Add the cookie to the response, user browser
                Response.Cookies.Add(cookie);
    
                HttpApplication application = new HttpApplication();
                HttpContext context = application.Context;
                System.Web.Security.FormsAuthenticationTicket ticketData = System.Web.Security.FormsAuthentication.Decrypt(cookie.Value);
                if (null != ticketData && !ticketData.Expired)
                {
                    context.User = new System.Security.Principal.GenericPrincipal(new System.Web.Security.FormsIdentity(ticketData), null);
                    context.Items.Add(userName, ticketData.UserData);
                }
    But it throwing error "object reference .." from context.User = new System.Security.Principal.GenericPrincipal(new System.Web.Security.FormsIdentity(ticketData), null);

    anmyone please help me out.

    Thanks.

    Ujjwal Das

  2. #2
    Non-Member
    Join Date
    Nov 2012
    Location
    pune
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <system.web>
    <authentication mode="Forms">
    <forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">
    </forms>
    </authentication>
    <authorization>
    </authorization>
    </system.web>
    using this code


Bookmarks

Posting Permissions

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