当前位置: 首页>>代码示例>>C#>>正文


C# ViewResult.ExecuteResult方法代码示例

本文整理汇总了C#中System.Web.Mvc.ViewResult.ExecuteResult方法的典型用法代码示例。如果您正苦于以下问题:C# ViewResult.ExecuteResult方法的具体用法?C# ViewResult.ExecuteResult怎么用?C# ViewResult.ExecuteResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.ViewResult的用法示例。


在下文中一共展示了ViewResult.ExecuteResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Application_Error

        //Обработка ошибок для всего приложения
        protected void Application_Error(object sender, EventArgs e)
        {
            string requestType=Request.RequestType;
            if (requestType.Equals("GET"))
            {
                HttpContext ctx = HttpContext.Current;
                Exception ex = ctx.Server.GetLastError();

                var httpException = ex as HttpException;
                if (httpException != null)
                {
                    if (httpException.GetHttpCode() == 404)
                    {
                        ctx.Response.Clear();

                        RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
                        IController controller = new HomeController(); // Здесь можно использовать любой контроллер
                        var context = new ControllerContext(rc, (ControllerBase)controller);

                        var viewResult = new ViewResult();

                        //страницы будут искаться в Views/Shared
                        viewResult.ViewName = "Error404";

                        viewResult.ViewData.Model = new HandleErrorInfo(ex, context.RouteData.GetRequiredString("controller"), context.RouteData.GetRequiredString("action"));
                        viewResult.ExecuteResult(context);
                        ctx.Server.ClearError();
                    }
                }
            }
        }
开发者ID:sergei-startsev,项目名称:GZ-webApp,代码行数:32,代码来源:Global.asax.cs

示例2: Application_Error

        protected void Application_Error()
        {
            try
            {
                var logger = ObjectFactory.GetInstance<ILog>();

                Exception exception = Server.GetLastError() ?? new Exception("Unable to get exception.");

                logger.Fatal("An unhandled exception occurred.", exception);
            }
            catch
            { }

            HttpContext ctx = HttpContext.Current;
            ctx.Response.Clear();
            RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
            string controllerName = rc.RouteData.GetRequiredString("controller");
            IControllerFactory factory = ControllerBuilder.Current.GetControllerFactory();
            IController controller = factory.CreateController(rc, controllerName);
            var cc = new ControllerContext(rc, (ControllerBase)controller);

            var viewResult = new ViewResult { ViewName = "Error" };
            viewResult.ExecuteResult(cc);
            ctx.Server.ClearError();
        }
开发者ID:escherrer,项目名称:EC2Utilities,代码行数:25,代码来源:Global.asax.cs

示例3: RedirectToError

        private static void RedirectToError()
        {
            HttpContext ctx = HttpContext.Current;
            var errorMessage = Convert.ToString(ctx.Server.GetLastError());

            var error = new KeyValuePair<string, object>("ErrorMessage", errorMessage);

            foreach (var er in ctx.AllErrors)
            {
                InternalLog.WriteLog(HttpContext.Current.Request.UserAgent,
                       HttpContext.Current.Request.Url.ToString(),
                       er.Message,
                       er.StackTrace.ToString());
            }

            ctx.Response.Clear();

            if (ctx.CurrentHandler != null && ctx.CurrentHandler.GetType().ToString().Equals("System.Web.Mvc.MvcHandler"))
            {
                RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
                IControllerFactory factory = ControllerBuilder.Current.GetControllerFactory();
                IController controller = factory.CreateController(rc, "Home");
                var cc = new ControllerContext(rc, (ControllerBase)controller);
                var viewResult = new ViewResult { ViewName = "InternalError" };
                viewResult.ViewData.Add(error);
                viewResult.ExecuteResult(cc);
                ctx.Response.End();
            }
        }
开发者ID:kiran3490,项目名称:SBSV.Web,代码行数:29,代码来源:Global.asax.cs

示例4: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var response = context.HttpContext.Response;
            var request = context.HttpContext.Request;

            var requestedUrl = GetRequestedUrl(request);
            NotFoundConfig.OnNotFound(context.RequestContext.HttpContext.Request, new Uri(requestedUrl));
            this.ViewData["RequestedUrl"] = requestedUrl;
            this.ViewData["ReferrerUrl"] = GetReferrerUrl(request, request.Url.OriginalString);

            // Make sure the status code is 404 for the search engine bots
            response.StatusCode = 404;

            // Prevent IIS7 from overwriting our error page!
            response.TrySkipIisCustomErrors = true;

            var viewResult = new ViewResult
            {
                ViewName = this.ViewName,
                ViewData = this.ViewData
            };
            response.Clear();
            viewResult.ExecuteResult(context);
        }
开发者ID:mrmashal,项目名称:NotFoundMvc,代码行数:29,代码来源:NotFoundViewResult.cs

示例5: Execute

        public void Execute(GenericResult genericResult, ControllerContext controllerContext)
        {
            if (genericResult.Refresh)
            {
                new RedirectResult(controllerContext.HttpContext.Request.RawUrl).ExecuteResult(controllerContext);
                return;
            }

            if (genericResult.RedirectUri != null)
            {
                new RedirectResult(genericResult.RedirectUri.ToString()).ExecuteResult(controllerContext);
                return;
            }

            var viewName = genericResult.ResultName ?? (string)controllerContext.RouteData.Values["action"];
            ViewEngineResult view = ViewEngines.Engines.FindView(controllerContext, viewName, null);
            if (view.View == null)
                return;

            var viewResult = new ViewResult();
            controllerContext.Controller.ViewData.Model = genericResult.Model;
            viewResult.ViewName = viewName;
            viewResult.ViewData = controllerContext.Controller.ViewData;
            viewResult.TempData = controllerContext.Controller.TempData;

            foreach (var message in genericResult.Messages.Where(m => m.Category == MessageCategory.Error))
                controllerContext.Controller.ViewData.ModelState.AddModelError(message.Field ?? message.Text, message.Text);

            viewResult.ExecuteResult(controllerContext);
        }
开发者ID:worldspawn,项目名称:ajaxcontinuations,代码行数:30,代码来源:ViewResultMapping.cs

示例6: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            var request = context.HttpContext.Request;

            // TODO: Add logic for not authorized requests
            string viewName = StatusCode == HttpStatusCode.NotFound ? NotFoundView : ErrorView;

            // We need to clear both headers and content
            // because Clear() doesn't clear the headers
            // see: http://msdn.microsoft.com/en-us/library/system.web.httpresponse.clear.aspx
            response.ClearHeaders();
            response.ClearContent();
            response.StatusCode = (int)StatusCode;

            // Certain versions of IIS will sometimes use their own error page when
            // they detect a server error. Setting this property indicates that we
            // want it to try to render ASP.NET MVC's error page instead.
            response.TrySkipIisCustomErrors = true;

            if (request.IsAjaxRequest())
            {
                // TODO: Add logic for AJAX requests
            }

            var viewResult = new ViewResult
            {
                ViewName = viewName,
                ViewData = ViewData ?? new ViewDataDictionary()
            };

            viewResult.ExecuteResult(context);
        }
开发者ID:shizik,项目名称:ScaffR-Generated,代码行数:33,代码来源:ErrorResult.cs

示例7: ExecuteResult

 private void ExecuteResult(ControllerBase controller)
 {
     var result = new ViewResult
                      {
                          ViewData = controller.ViewData,
                          TempData = controller.TempData
                      };
     result.ExecuteResult(controller.ControllerContext);
 }
开发者ID:gatepoet,项目名称:DeiCon.MvcValidation,代码行数:9,代码来源:LoadViewModelAttribute.cs

示例8: Execute

        public override void Execute(object model, ControllerContext context)
        {
            context.HttpContext = new HttpContextWrapper(HttpContext.Current);
            var viewResult = new ViewResult {TempData = context.Controller.TempData, ViewData = context.Controller.ViewData};

            viewResult.ViewData.Model = null;

            viewResult.ExecuteResult(context);
        }
开发者ID:adamjmoon,项目名称:Siege,代码行数:9,代码来源:ViewResponse.cs

示例9: View

 private new ActionResult View(string viewFolder, string viewName, object model = null)
 {
     var view = new ViewResult();
     view.TempData = TempData;
     view.ViewName = (viewFolder != null ? ("~/Views/" + viewFolder + "/" + viewName + ".cshtml") : viewName);
     view.ViewData = ViewData;
     view.ViewData.Model = model;
     view.ExecuteResult(ControllerContext);
     return null;
 }
开发者ID:exsurgo,项目名称:syncjs,代码行数:10,代码来源:AppController.cs

示例10: Application_Error

        protected void Application_Error()
        {
            ErrorLoger.LogEventError(Server.GetLastError());
            ErrorLoger.LogEventError(Context.Error);

            Response.Clear();
            Server.ClearError();

            var res = new ViewResult {ViewName = "Error"};
            res.ExecuteResult(new ControllerContext(Request.RequestContext, (ControllerBase) new HomeController()));
        }
开发者ID:Apostol59,项目名称:Endowment,代码行数:11,代码来源:Global.asax.cs

示例11: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            HttpContext ctx = HttpContext.Current;
            Exception ex = ctx.Server.GetLastError();
            ctx.Response.Clear();

            RequestContext rc = ((MvcHandler) ctx.CurrentHandler).RequestContext;

            IController controller = new ErrorController();

            var context = new ControllerContext(rc, (ControllerBase) controller);

            var viewResult = new ViewResult();
            if (ex is HttpRequestValidationException)
                viewResult.ViewName = "HttpRequestValidationException";
            else
            {
                var httpException = ex as HttpException;

                if (httpException != null)
                {
                    switch (httpException.GetHttpCode())
                    {
                        case 404:
                            viewResult.ViewName = "Error404";
                            break;

                        case 500:
                            viewResult.ViewName = "Error500";
                            break;

                        default:
                            viewResult.ViewName = "Error";
                            break;
                    }
                }
                else
                {
                    viewResult.ViewName = "Error";
                }
            }

            context.RouteData.Values["controller"] = "Error";
            context.RouteData.Values["action"] = viewResult.ViewName;
            context.RouteData.Values["exception"] = ex;

            viewResult.ViewData.Model = new HandleErrorInfo(ex, context.RouteData.GetRequiredString("controller"),
                                                            context.RouteData.GetRequiredString("action"));
            log.Error(ex.Message);
            viewResult.ExecuteResult(context);
            ctx.Server.ClearError();
        }
开发者ID:vladimir0ne1,项目名称:AddressBook,代码行数:52,代码来源:Global.asax.cs

示例12: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            HttpContext httpContext = HttpContext.Current;

            // Для администратора отображаем стандартный вывод ошибки
            if (httpContext.User != null &&
                httpContext.User.Identity != null &&
                httpContext.User.Identity.IsAuthenticated)
            {
                return;
            }

            Exception ex = httpContext.Server.GetLastError();
            httpContext.Response.Clear();

            if (new HttpRequestWrapper(Request).IsAjaxRequest())
            {
                Response.StatusCode = 500;
                Response.ContentType = "application/json";
                Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new
                {
                    errorMessage = ex.Message
                }));

                return;
            }

            RequestContext requestContext = ((MvcHandler)httpContext.CurrentHandler).RequestContext;
            IController controller = new HomeController();
            var context = new ControllerContext(requestContext, (ControllerBase)controller);

            ViewResult viewResult = new ViewResult();
            HttpException httpException = ex as HttpException;

            if (httpException != null)
            {
                viewResult.ViewBag.HttpCode = httpException.GetHttpCode();

                // Исправляем ошибку ELMAH (Request Validation errors does not get logged)
                // https://code.google.com/p/elmah/issues/detail?id=217
                if (httpException is HttpRequestValidationException)
                {
                    Elmah.ErrorLog.GetDefault(httpContext).Log(new Error(httpException));
                }
            }

            viewResult.ViewName = "Error";
            viewResult.ViewData.Model = new HandleErrorInfo(ex, context.RouteData.GetRequiredString("controller"), context.RouteData.GetRequiredString("action"));
            viewResult.ExecuteResult(context);
            httpContext.ClearError();
        }
开发者ID:OrenTiger,项目名称:my-personal-blog,代码行数:51,代码来源:Global.asax.cs

示例13: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            try
            {
                HttpContext ctx = HttpContext.Current;
                Exception ex = ctx.Server.GetLastError();
                ctx.Response.Clear();

                RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
                IController controller = new HomeController();
                // Тут можно использовать любой контроллер, например тот что используется в качестве базового типа
                var context = new ControllerContext(rc, (ControllerBase)controller);

                var viewResult = new ViewResult();

                var httpException = ex as HttpException;
                if (httpException != null)
                {
                    switch (httpException.GetHttpCode())
                    {
                        case 404:
                            viewResult.ViewName = "Error404";
                            break;

                        case 401:
                            viewResult.ViewName = "Error401";
                            break;

                        default:
                            viewResult.ViewName = "Error";
                            break;
                    }
                }
                else
                {
                    viewResult.ViewName = "Error";
                }

                viewResult.ViewData.Model = new HandleErrorInfo(ex, context.RouteData.GetRequiredString("controller"),
                    context.RouteData.GetRequiredString("action"));
                viewResult.ExecuteResult(context);
                ctx.Server.ClearError();
            }
            catch (Exception)
            {
                var viewResult = new ViewResult();
                viewResult.ViewName = "Error";
                //throw;
            }
           
        }
开发者ID:bashnia007,项目名称:tourismgroup361,代码行数:51,代码来源:Global.asax.cs

示例14: HandleUnknownAction

        protected override void HandleUnknownAction(string actionName)
        {
            var controllerName = (string)RouteData.Values["controller"];
            var ex = Server.GetLastError();
            var model = new HttpErrorViewModel(ex ?? new HttpException(500, "Something went wrong."), controllerName, actionName);
            var result = new ViewResult
            {
                ViewName = "~/Views/Error/Index.cshtml",
                ViewData = new ViewDataDictionary<HttpErrorViewModel>(model),
            };

            Response.StatusCode = model.StatusCode;
            result.ExecuteResult(ControllerContext);
        }
开发者ID:jonantoine,项目名称:gcr,代码行数:14,代码来源:ErrorController.cs

示例15: OnException

        public void OnException(ExceptionContext filterContext)
        {
            HttpContext ctx = HttpContext.Current;
            Exception ex = ctx.Server.GetLastError();
            ctx.Response.Clear();

            RequestContext rc = ((MvcHandler)ctx.CurrentHandler).RequestContext;
            IController controller = new HomeController(); // Здесь можно использовать любой контроллер
            var context = new ControllerContext(rc, (ControllerBase)controller);

            var viewResult = new ViewResult();

            var httpException = ex as HttpException;
            if (httpException != null)
            {
                switch (httpException.GetHttpCode())
                {
                    //страницы будут искаться в Views/Shared
                    case 404:
                        viewResult.ViewName = "Error404";
                        break;

                    case 500:
                        viewResult.ViewName = "Error500";
                        break;

                    default:
                        viewResult.ViewName = "Error";
                        break;
                }
            }
            else
            {
                viewResult.ViewName = "Error";
            }

            viewResult.ViewBag.Message = filterContext.Exception.Message;

            //logging
            HttpSessionStateBase sessionBase = new HttpSessionStateWrapper(ctx.Session);
            AppLogger.Error(sessionBase, filterContext.Exception.Message);

            try{
                viewResult.ViewBag.TargetSite = filterContext.Exception.TargetSite;
                viewResult.ViewBag.StackTrace = filterContext.Exception.StackTrace;
            }catch(Exception e){}

            viewResult.ExecuteResult(context);
            ctx.Server.ClearError();
        }
开发者ID:sergei-startsev,项目名称:GZ-webApp,代码行数:50,代码来源:ClientErrorHandler.cs


注:本文中的System.Web.Mvc.ViewResult.ExecuteResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。