Hi I am getting this error when trying to redirect my page to the login page.
public ActionResult Index() {
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
//0 Username | 1 Fullname | 2 User Id | 3 Login Type | 4 Election Id
string[] UserData = ticket.UserData.Split('|');
if (UserData[3] == null)
{
FormsAuthentication.SignOut();
return RedirectToAction("login", "login");
}
And the error is :
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 22: Line 23: public ActionResult Index() { Line 24:
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value); Line 25: //0 Username | 1 Fullname | 2 User Id | 3 Login Type | 4 Election Id Line 26: string[] UserData = ticket.UserData.Split('|');Source File: C:\Elections\Elections2014\Controllers\ffs\ffsInventoryController.cs
Line: 24