Skip to content

Commit a51ae39

Browse files
author
N. Taylor Mullen
committed
Adjust context property on RazorView.
Context is now HttpContext which pulls from ViewContext which is now a member. aspnet#377
1 parent 51155fb commit a51ae39

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/Microsoft.AspNet.Mvc.Razor/RazorView.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Security.Principal;
1111
using System.Text;
1212
using System.Threading.Tasks;
13+
using Microsoft.AspNet.Http;
1314
using Microsoft.AspNet.Mvc.Rendering;
1415
using Microsoft.Framework.DependencyInjection;
1516

@@ -22,7 +23,20 @@ public abstract class RazorView : IView
2223

2324
public IViewComponentHelper Component { get; private set; }
2425

25-
public ViewContext Context { get; set; }
26+
public HttpContext Context
27+
{
28+
get
29+
{
30+
if (ViewContext == null)
31+
{
32+
return null;
33+
}
34+
35+
return ViewContext.HttpContext;
36+
}
37+
}
38+
39+
public ViewContext ViewContext { get; set; }
2640

2741
public string Layout { get; set; }
2842

@@ -34,20 +48,20 @@ public virtual IPrincipal User
3448
{
3549
get
3650
{
37-
if (Context == null || Context.HttpContext == null)
51+
if (Context == null)
3852
{
3953
return null;
4054
}
4155

42-
return Context.HttpContext.User;
56+
return Context.User;
4357
}
4458
}
4559

4660
public dynamic ViewBag
4761
{
4862
get
4963
{
50-
return (Context == null) ? null : Context.ViewBag;
64+
return (ViewContext == null) ? null : ViewContext.ViewBag;
5165
}
5266
}
5367

@@ -60,7 +74,7 @@ public dynamic ViewBag
6074
public virtual async Task RenderAsync([NotNull] ViewContext context)
6175
{
6276
SectionWriters = new Dictionary<string, HelperResult>(StringComparer.OrdinalIgnoreCase);
63-
Context = context;
77+
ViewContext = context;
6478

6579
InitHelpers();
6680

@@ -100,16 +114,17 @@ public virtual async Task RenderAsync([NotNull] ViewContext context)
100114

101115
private void InitHelpers()
102116
{
117+
Contract.Assert(ViewContext != null);
103118
Contract.Assert(Context != null);
104119

105-
Url = Context.HttpContext.RequestServices.GetService<IUrlHelper>();
120+
Url = Context.RequestServices.GetService<IUrlHelper>();
106121

107-
Component = Context.HttpContext.RequestServices.GetService<IViewComponentHelper>();
122+
Component = Context.RequestServices.GetService<IViewComponentHelper>();
108123

109124
var contextable = Component as ICanHasViewContext;
110125
if (contextable != null)
111126
{
112-
contextable.Contextualize(Context);
127+
contextable.Contextualize(ViewContext);
113128
}
114129
}
115130

0 commit comments

Comments
 (0)