0

I strucked with this problem for past 2 days. My MVC project is using the form authentication. I set the timeout as 1 min (just for testing). It sucessfully get timeout. Because after one minute pages not working. But i need to redirect to my login page. I gave login url in form authentication. But it won't works. Any body please suggest me the solution for this problem. The code as follows

<authentication mode="Forms">

<forms loginUrl="~/Login/Login" path="/" timeout="1" protection="All" />

</authentication>

The error shows in the following code when get timeout. By this error only i found that the timeout will be occur successfully but the redirection is only in a problem.

public ActionResult Employee()
        {



            mod.StateDetails = objentity.ExecuteFunction<GetStateDetails_Result>("GetStateDetails").ToList();
            List<ObjectParameter> lstParam = new List<ObjectParameter>();
            int Divsion = Convert.ToInt32(logmodel.getDivisionId().ToString());
            ObjectParameter objparam5 = new ObjectParameter("Division", Divsion);
            lstParam.Add(objparam5);
            mod.custinfo = objentity.ExecuteFunction<GetCustomerInfoByDivision_Result>("GetCustomerInfoByDivision", lstParam.ToArray()).ToList();
            mod.SkillInfo = objentity.ExecuteFunction<GetSkillInfo_Result>("GetSkillInfo").ToList();
            mod.DivisionDetails = objentity.ExecuteFunction<GetDivisionDetails_Result>("GetDivisionDetails").ToList();
            int roleid = Convert.ToInt32(logmodel.getRoleId().ToString());
            mod.RoleId = roleid;
            return View(mod);
        }

Thanks in Advance

10
  • Are you sure your loginUrl is ~/Login/Login rather than ~/Account/Login? Commented Jul 12, 2012 at 7:13
  • What happens when the authentication cookie expires? Aren't you redirected to the LogOn page? Commented Jul 12, 2012 at 7:13
  • @Jeow Li Huan: I am sure about my URL. Commented Jul 12, 2012 at 7:14
  • @Darin Dimitrov It Shows error like "Object reference not set to an instance of an object." in the code. Commented Jul 12, 2012 at 7:15
  • In which code? Did you decorate your controller actions with the [Authorize] attribute? Commented Jul 12, 2012 at 7:16

1 Answer 1

1

You have to decorate your controller action with the [Authorize] attribute if you want the user to be redirected when accessing a controller action that requires authentication:

[Authorize]
public ActionResult Employee()
{
    mod.StateDetails = objentity.ExecuteFunction<GetStateDetails_Result>("GetStateDetails").ToList();
    List<ObjectParameter> lstParam = new List<ObjectParameter>();
    int Divsion = Convert.ToInt32(logmodel.getDivisionId().ToString());
    ObjectParameter objparam5 = new ObjectParameter("Division", Divsion);
    lstParam.Add(objparam5);
    mod.custinfo = objentity.ExecuteFunction<GetCustomerInfoByDivision_Result>("GetCustomerInfoByDivision", lstParam.ToArray()).ToList();
    mod.SkillInfo = objentity.ExecuteFunction<GetSkillInfo_Result>("GetSkillInfo").ToList();
    mod.DivisionDetails = objentity.ExecuteFunction<GetDivisionDetails_Result>("GetDivisionDetails").ToList();
    int roleid = Convert.ToInt32(logmodel.getRoleId().ToString());
    mod.RoleId = roleid;
    return View(mod);
}

The Authorize attribute will verify if the user supplied a valid authentication cookie and if not redirect him to the Login page that you specified in your web.config file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.