Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
i have one question. I have some controllers in my project and i try to created redirect this actions to one View. I want to create this option in special cases for example: I want, blocked application on 5 minutes in date 18/08/2014 at 21:00. In this time you can't nothing to do, when you try click on button "Add new product" or "Edit product" you are redirect to new page with information "Sorry, application is off".

My conception is that, create Global action filter with condition where i check for example if datetime 18/08/2014 21:00 is true then redirect to View with information , else continue work.

This is good conception ?

What are you think about that ?
Maybe you have other solution?
Posted

1 solution

First you need to create a Controller and view for error message like
SQL
public class HomeController : BaseController
{
    public ActionResult Index()
        {
            ViewBag.Message = TempData["Message"];
            return View();
        }
    public ActionResult ErrorMessage()
        {
            TempData["Message"] = "Sorry, application is off";

            return RedirectToAction("Index");
        }
}


Then Create a Action Filter like

C#
public class ApplicationAuthorise : AuthorizeAttribute
    {

        public override void OnAuthorization(AuthorizationContext filterContext)
        {

            if (AppLockedDate==true)
            {
                filterContext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary {
                        { "Controller", "Home" },
                        { "Action", "ErrorMessage" }
                        });
            }


        }
    }



Apply authorization attribute to your actions as

SQL
[ApplicationAuthorise]
        public ActionResult ShowDetails()
        {
            return View();
        }


I hope it works.
 
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