From a51ae39693c1b5e464db97c3787c35ff76e6ffa3 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 9 May 2014 11:52:22 -0700 Subject: [PATCH] Adjust context property on RazorView. Context is now HttpContext which pulls from ViewContext which is now a member. #377 --- src/Microsoft.AspNet.Mvc.Razor/RazorView.cs | 31 +++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index 80c5bce66f..e7ce1f7c7e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -10,6 +10,7 @@ using System.Net; using System.Security.Principal; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.Framework.DependencyInjection; @@ -22,7 +23,20 @@ namespace Microsoft.AspNet.Mvc.Razor public IViewComponentHelper Component { get; private set; } - public ViewContext Context { get; set; } + public HttpContext Context + { + get + { + if (ViewContext == null) + { + return null; + } + + return ViewContext.HttpContext; + } + } + + public ViewContext ViewContext { get; set; } public string Layout { get; set; } @@ -34,12 +48,12 @@ namespace Microsoft.AspNet.Mvc.Razor { get { - if (Context == null || Context.HttpContext == null) + if (Context == null) { return null; } - return Context.HttpContext.User; + return Context.User; } } @@ -47,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.Razor { get { - return (Context == null) ? null : Context.ViewBag; + return (ViewContext == null) ? null : ViewContext.ViewBag; } } @@ -60,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor public virtual async Task RenderAsync([NotNull] ViewContext context) { SectionWriters = new Dictionary(StringComparer.OrdinalIgnoreCase); - Context = context; + ViewContext = context; InitHelpers(); @@ -100,16 +114,17 @@ namespace Microsoft.AspNet.Mvc.Razor private void InitHelpers() { + Contract.Assert(ViewContext != null); Contract.Assert(Context != null); - Url = Context.HttpContext.RequestServices.GetService(); + Url = Context.RequestServices.GetService(); - Component = Context.HttpContext.RequestServices.GetService(); + Component = Context.RequestServices.GetService(); var contextable = Component as ICanHasViewContext; if (contextable != null) { - contextable.Contextualize(Context); + contextable.Contextualize(ViewContext); } }