Search code examples
asp.netangularjsasp.net-mvcresponse.redirect

Detecting redirect to a different URL


I am using ASP.NET MVC with AngularJs framework. In my home controller I'm checking if there is a valid license and if not, I'm re-directing to a page to import license with this code:

public ActionResult Index()
        {
            var retVal = _licenseProvider.ValidateExistingLicense();

            if (!retVal.Item1)
            {                
                Response.Redirect("DataMaintenance/ImportLicenses", true);
                return View("DataMaintenance/ImportLicenses");
            }

So, in my ImportLicenses controller I want to detect that I was re-directed vs. called from the menu. I found an older thread about redirecting to a different action, but that solution doesn't apply. What are my options here?


Solution

  • In the meanwhile I decided to do a little bit of cheating, but it worked. In the menu I changed the original call to this

     dataMaintNodes.SubNodes.Add(new MenuMapNode() { LabelKey = "importLicense", Action = "ImportLicenses", Controller = "ImportLicenses", Area = "DataMaintenance", Icon = "", Roles = "IMPORTLIC" });

    In other words, instead of normal Index action I introduced a different action. I added that new action to my controller and just set the ViewBag property to false when called from the menu and to true in the Index action that is called by Redirect. So, it's a cheating, but it works. I only wanted to display Cancel button on that modal dialog when I am calling from the regular menu and no Cancel button when called from the home controller. Now, my second problem is that Modal Dialog doesn't really prevent from escaping from it and continuing working with the application. So, we may want to introduce more logic.