How to properly authenticate mvc-mini-profiler with AspNetSqlMembershipProvider

后端 未结 3 823
心在旅途
心在旅途 2021-02-04 07:57

I tried to check if the user is in role at Application_BeginRequest and Application_AuthenticateRequest with this code and it will not work. At BeginRequest the code is never hi

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 08:47

    This is my 2cent.

            context.AcquireRequestState += (sender, e) =>
            {
                // Check debug in session. Can be set from Querystring. (?debug=true)
                if (HttpContext.Current.Session != null && HttpContext.Current.Session["Debug"] != null)
                {
                    try{
                        bool debug = (bool)HttpContext.Current.Session["Debug"];
                        if (debug == true) 
                            MiniProfiler.Start();
                        else 
                            MiniProfiler.Stop(discardResults: true);
                    }
                    catch{ 
                        MiniProfiler.Stop(discardResults: true);
                    }
    
                }// Or always show if Administrator.
                else if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    bool admin = HttpContext.Current.User.IsInRole("Administrator");
                    if (admin == false)
                    {
                        MiniProfiler.Stop(discardResults: true);
                    }
                }
                else
                {
                    MiniProfiler.Stop(discardResults: true);
                }
            };
    

提交回复
热议问题