localhost redirected you too many times in mvc

折月煮酒 提交于 2020-03-25 19:12:22

问题


i have written a code with a condition in global asax but what is happening is when the condition becomes true the codes goes infinity loops and runs there and there the code is as follows:::In Route.Config

    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("favicon.ico");
            routes.IgnoreRoute("favicon-zurich.ico");
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                //defaults: new { controller = "Home", action = "IndexSideMenu", id = UrlParameter.Optional }
                defaults: new { controller = "ClientEnquiry", action = "ScheduleList", id = UrlParameter.Optional }
            );
        }

    }





public class UnderMaintenanceAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var requestTimestamp = filterContext.HttpContext.Timestamp;

            filterContext.Result = new RedirectToRouteResult(
                // create your controller/action/view to display your message
                new RouteValueDictionary
                {
                    { "controller", "Undermaintenance" },
                    { "action", "Maintenance" }
                });

        }
    }


The code in global asax and the condition is as follows

public void Application_PostAuthorizeRequest()
        {
            System.Web.HttpContext.Current.
                SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
            string sTime = System.Configuration.ConfigurationManager.AppSettings["StartTime"].ToString();
            string eTime = System.Configuration.ConfigurationManager.AppSettings["EndTime"].ToString();
            DateTime nTime = DateTime.Now;
            var startHour = Int32.Parse(sTime);
            var endHour = Int32.Parse(eTime);
            if (nTime.Hour < startHour || nTime.Hour >= endHour)
            {
                try
                {
                    InvokeUnderMaintenance();
                }
                catch (Exception e)
                {
                    Console.WriteLine("exception of c" + e);
                }

            }

        }

        public void InvokeUnderMaintenance()
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }

the filter.config is as follows

public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new UnderMaintenanceAttribute());
        }
    }

the problems is while debugging its just roaming der and der only and finally giving the output of webpage too many redirects try clear ur cookies i tried that option too but no working can anyone please help me out of this

来源:https://stackoverflow.com/questions/60070557/localhost-redirected-you-too-many-times-in-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!