private HtmlResult RenderNotFound(IHttpRequest request) { if (request.Session.ContainsParameter("auth")) { return(new HtmlResult(_viewEngine.RenderError("404 NotFound", ((IIdentity)request.Session.GetParameter("auth")).Role), HttpStatusCode.NotFound)); } return(new HtmlResult(_viewEngine.RenderError("404 NotFound", "Guest"), HttpStatusCode.NotFound)); }
protected virtual IViewable View([CallerMemberName] string actionName = default) { string controllerName = GetType().Name.Replace(MvcContext.ControllersSuffix, string.Empty); string viewContent; try { viewContent = ViewEngine.RenderView(controllerName, actionName, PropertyBag); } catch (Exception e) { viewContent = ViewEngine.RenderError(e.Message, PropertyBag["role"].ToString()); } return(new ViewResult(new View(viewContent))); }
public void TestRenderError(string error) { ViewEngine viewEngine = ViewEngineSetup.SetupViewEngine(viewPath => { if (viewPath.EndsWith("_Layout.html")) { return("<html><head></head><body>@Error()</body></html>"); } if (viewPath.EndsWith("_Error.html")) { return("<h1>@Error</h1>"); } throw new NotSupportedException("View path has unsupported ending"); }); Assert.That(viewEngine.RenderError(error), Is.EqualTo($"<html><head></head><body><h1>{error}</h1></body></html>")); }