How can I disable the view of a page for other users?

108 Views Asked by At

I want that a user of my application to enable or disable the viewing of a certain page for other users. For that i need , somehow an application variable, a bool to be set true or false whether the user decides to enable or disable the view for other users.

The functionality that i want is : when i click on a button to disable the view for a page(for other users that are connected to site), and when i press back to enable it .

I can achieve this with the use of a database, by changing the value of a field in a table with true or false.But this approach is ineffective and not elegant.

Can someone tell me how I can achieve this without using databases ? Is there any application variable / session variable / or cookie to achieve this ? Is there something that i should write in Global.asax ?

I use ASP.NET MVC 4..

Please help!

1

There are 1 best solutions below

5
On

In you Controller declare "static variable" say

static bool disableViewPage;

Set this value on click of button in the some action.

Example :

public class SomeViewController : Controller
{
   [HttpPost]
   public ActionResult DisableView(bool value)// on button click
   {
      SecondController.DisableViewPage=value;
      return View("<SomeView>")
   }

}

public class SecondController : Controller
{
   public static bool DisableViewPage;
   // your views

}