To achive this I had use cookies.The approch I follow is below
Create a BaseController Class and inherit all your controller with this BaseController.
In your BaseController ,Override onActionExecuting Method like below
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
string value =cookie
base.OnActionExecuting(filterContext);
string controllerName = filterContext.Controller.GetType().Name;
string actionName = filterContext.ActionDescriptor.ActionName;
if (string.IsNullOrEmpty(value))
{
if (!controllerName.Equals(typeof(LoginController).Name))
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{ "Controller", "Login" },
{ "Action", "Index" }
});
}
else
{
if (string.IsNullOrEmpty(Session["UserId"])
{
}
}
}