If user is logged in I want to show my department view, if not logged in want to show login page. I have tried something like this inside my RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
if (HttpContext.Current.User==null)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}
else
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Department", action = "Index", id = UrlParameter.Optional }
);
}
}
But this one always loads login page at startup.Can anyone point out what I am doing wrong here? Note: I am using Asp.net Identity for this application
HttpContext.Current.Userfor null. It is incorrect and will give you wrong results.