Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a login page . after login i am redirected to a dashboard Page. After logout ,if i enter the url in the address bar, the page is showing. How can i prevent this in MVC project?

Can anybody help me

What I have tried:

I tried by using action filters
Posted
Updated 21-Feb-16 22:39pm
Comments
F-ES Sitecore 19-Feb-16 5:47am    
Disable caching on your dashboard page, google "mvc disable caching" for code samples. This will adversely affect the performance of your web site though, just to stop someone seeing something they've already seen...I'd personally just ignore the issue.
Kunjammu 19-Feb-16 6:02am    
after logout some other person use the system and can see the url rignt?
it will be an issue? I am trying to solve this
F-ES Sitecore 19-Feb-16 6:04am    
Can people always view the page, even when not logged in? If you ctrl+f5 in the browser does the page show? If so it's a caching issue, if they can always see the page you need to enable authorisation on that page.
Kunjammu 19-Feb-16 6:11am    
not in a single page. after logout if we type any url of that site should redirect to login page. is there any method for doing globally
John C Rayan 19-Feb-16 5:59am    
Use [Authorize] action filer in your action. If you have different roles, then you have to specify the roles too.

Have a look at this. You need to learn first before applying it

Custom Authentication and Authorization in ASP.NET MVC[^]
 
Share this answer
 
v2
There are three ways for doing that functionality which i m already using in my own project:
(1):Add this code to your every "ActionResult" method. By using this user can not go back by clicking backward icon of browser after "LogOut"
C#
public void SetPageCacheNoStore()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.AppendCacheExtension("no-store, must-revalidate");
    Response.AppendHeader("Pragma", "no-cache");
    Response.AppendHeader("Expires", "0");
}


(2):Use this code in every method at startup for checking Session destroyed or not.
C#
if (Session["UserName"] == null)
                {
                    return RedirectToAction("Login", "Account");
                }

(3):Use this code in every view or in a "Partial" view like "Sidebar uses in every view".
string viewNames = Session["UserName"];
   if (ViewNames == null)
   {
       <script src="~/Scripts/jquery-1.11.1.min.js"></script>
       <script>
           $(document).ready(function () {
               window.location.href = "../Account/Login";
           });
       </script>

   }


I hope by using all of these solutions your problem will be resolved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900