Pravinkumar Birajdar

Pravinkumar Birajdar

  • 1.1k
  • 584
  • 109.4k

Session checking in _Layout page in mvc

May 1 2020 2:39 AM
In my _Layout page, I have added following code before @RenderBody()
  1.  @if (Session["UserID"].ToString() != "" || Session["UserID"]!=null)  
  2.  {  
  3.       if (Session["RoleID"].ToString() == "2")  
  4.       {  
  5.            //menus here  
  6.       }  
  7.                               
  8. }  
  9. else  
  10. {  
  11.     Response.Redirect("~/Account/login");  
  12. }  
 but still it is not redirecting to login when Session["UserID"] is empty & it is rendering @RenderBody()
 
I downt want to call @RenderBody() is  Session["UserID"] is empty.
 
please help me out 

Answers (2)