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:



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

<system.web>
<authentication mode=“Forms”>
<forms loginUrl=“Logon.aspx” name=“.ASPXFORMSAUTH”>
</forms>
</authentication>
<authorization>
</authorization>
</system.web>
using this code