微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ASP.NET MVC中的自定义路由绕过Home Controller / Index

如何解决ASP.NET MVC中的自定义路由绕过Home Controller / Index

我当前的网站要求用户在访问子菜单之前先选择餐厅类型。

例如,当用户尝试直接访问http://localhost:8888/Restaurant/KFcmenu/?id=KFCCurlyFries时 他们将被重定向到此页面http://localhost:8888/Restaurant/Home

我想在此提及的逻辑是,因为他们要访问KFC Curly Fries菜单(在参数中),因此路线应基于该参数自动分配餐厅类型,并跳过Home controller/Index进行选择

我可以知道在这种情况下如何编写自定义路由来绕过Home控制器/索引吗?

这是我在RouteConfig.cs中的认路由

routes.MapRoute(
name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "UserLogin",action = "Index",id = UrlParameter.Optional }
);

更新

我的餐厅管理员

 public class RestaurantController: Controller
    {
        public ActionResult Index(HomeModel vm,string btnModeMcd,string btnModeKFC,string btnModePizzaHut,string Menu)
        {
            if (!string.IsNullOrWhiteSpace(Menu))
            {
                TempData["Success"] = "<script>Swal({" +
                            "title: 'Access Denied'," +
                            "text: 'Access Denied for " + Menu + " Menu'," +
                            "type: 'warning'," +
                            "timer: 2500," +
                            "confirmButtonColor: '#5cb85c'," +
                            "cancelButtonColor: '#3085d6'," +
                            "confirmButtonText: 'OK'," +
                            "cancelButtonText: 'New Menu'" +
                        "});</script>";
            }

            if (string.IsNullOrWhiteSpace((string)Session["MODE"]))
            {
                Session["MODE"] = "Mcd";
            } 

            if (btnModeMcd != null)
            {
                Session["MODE"] = "Mcd";
            }

            if (btnModeKFC != null)
            {
                Session["MODE"] = "KFC";
            }

            if (btnModePizzaHut != null)
            {
                Session["MODE"] = "PizzaHut";
            }
            
            vm.Mode = (string)Session["MODE"];
            return View(vm);
        }
        
        public ActionResult About()
        {
            ViewBag.Message = "Your description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult AccessDenied(string Menu)
        {
            TempData["Success"] = "<script>Swal({" +
                        "title: 'Access Denied'," +
                        "text: 'Access Denied for " + Menu + " Menu'," +
                        "type: 'warning'," +
                        "timer: 2500," +
                        "confirmButtonColor: '#5cb85c'," +
                        "cancelButtonColor: '#3085d6'," +
                        "confirmButtonText: 'OK'," +
                        "cancelButtonText: 'New Menu'" +
                    "});</script>";
            return View();
        }
    }

解决方法

您还有很多事情要做,而您的表现不足以得出实际答案

TokenValidationParameters

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。