コード例 #1
0
        /// <summary>
        /// This method will fire everytime
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnException(ExceptionContext filterContext)
        {
            string UserName = "";

            if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null)
            {
                UserName = LoginUser.GetUserName();
            }

            string ErrorCode = Codes.GetErrorCode();

            log4net.GlobalContext.Properties["ErrorCode"] = ErrorCode;
            Logger.Error(filterContext.Exception);

            //This will execute in case Non Ajax call
            //if (!filterContext.HttpContext.Request.IsAjaxRequest())
            //{
            var CustomError = System.Configuration.ConfigurationManager.AppSettings["ShowCustomErrorPage"];

            if (CustomError != null && CustomError.ToString() == "true")
            {
                if (filterContext.HttpContext.Response.StatusCode != 404)
                {
                    var routeData = new RouteData();
                    routeData.Values["controller"] = "Error";
                    routeData.Values["action"]     = "PageNotFoundError";

                    //IController errorsController = new
                    var exception     = HttpContext.Current.Server.GetLastError();
                    var httpException = exception as HttpException;

                    // assigning new route to controls
                    var rc = new RequestContext
                             (
                        new HttpContextWrapper(HttpContext.Current),
                        routeData

                             );
                    rc.RouteData.Values.Add("ErrorCode", ErrorCode);

                    //errorsController.Execute(rc);
                    filterContext.ExceptionHandled = true;
                }
            }
        }
コード例 #2
0
        public static Guid GetUserId()
        {
            if (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated && LoginUser.GetUserName() != "")
            {
                try
                {
                    Guid userId = Guid.Empty;

                    HttpCookie UserCookie = new HttpCookie("User");
                    UserCookie = HttpContext.Current.Request.Cookies["User"];
                    if (UserCookie != null)
                    {
                        string user = UserCookie.Value.ToString();
                        user   = user.DecryptData();
                        userId = new Guid(user);
                    }
                    else
                    {
                        AVOAIALifeEntities entities = new AVOAIALifeEntities();
                        string             UserName = LoginUser.GetUserName();
                        var user = entities.tblUserDetails.FirstOrDefault(a => a.LoginID == UserName);
                        if (user == null)
                        {
                            return(new Guid());
                        }
                        userId = new Guid(user.UserID.ToString());
                    }
                    return(userId);
                }
                catch (Exception ex)
                {
                    return(new Guid());
                }
            }
            else
            {
                return(new Guid());
            }
        }