1

We have a web application with multi user admin panel built using ASP.NET MVC. Since multiple users access same page at the same time, only the last edited and saved user's data will be updated to the database. This creates problem to the other users.

  1. Is there any option to disallow concurrent access of users to the same page at any time? If a user is already working on a page, the system should alert other user who is trying to access the same page that "Someone else is working on this page. Please try after some time."
  2. Is there any facility for this issue provided by the MVC framework itself or the .NET Authentication?
  3. Otherwise, any suitable logical solution is also fine.

Thanks in advance...

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • You can do it in the Db level. If someone is already editing the page or form, just use a bit column to prevent concurrent editing. In this case, you can create another or in the same table. Just update the column 1 while updating and 0 when done. – AT-2017 Oct 11 '16 at 06:58
  • @AT-2016, Does not work if the first user abandons the edit - the flag is never reset and no one else ca ever edit it :) –  Oct 11 '16 at 07:52
  • if some one access the page and I updated the bit field to 1 and he left the page without clicking the submit button. the page will become unusable to all the users indefinitely. right? – Nobin Thomas Oct 11 '16 at 07:52
  • Possible duplicate of [asp.net mvc; edit option only for one user at a time](http://stackoverflow.com/questions/25173790/asp-net-mvc-edit-option-only-for-one-user-at-a-time) –  Oct 11 '16 at 07:55
  • That's true @Stephen Muecke. I was actually thinking about the edit of the stackoverflow.com. The edit is denied when someone already has done with it. It could be similar but requires third person to modify it. – AT-2017 Oct 11 '16 at 07:56
  • You can use SignalR to detect when the user abandons the edit (and when they have finished with the edit to inform your other users that it's now available) http://stackoverflow.com/a/15000450/2181514 – freedomn-m Oct 11 '16 at 08:13

1 Answers1

0

create table like sys_forms this table has column like controller and action and view and isActive

and adding action filter when you need check if page is available or not

[PageAvailableFilter]
 public class HomeController : Controller
 {
      public ActionResult Index()
      {
           return View();
      }
 }

and create PageAvailableFilter class Inherited from ActionFilterAttribute and override OnActionExecuting method because this method invoked before actions in controller

public class PageAvailableFilterFilter : ActionFilterAttribute

 {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
           var controllerName = filterContext.routeData.Values["controller"];
           var actionName = filterContext.routeData.Values["action"];
           //here and you logic and query
           if (some_conditions == true)
           {
            filterContext.Result = new RedirectResult("~/MyPage");
            return;
           }
      }
  }

and check if this controller and action is available or not and you can use viewbag and viewdata in this class

to more information read more about action filter

Ibrahim Alsurkhi
  • 113
  • 1
  • 13