Add User helper to controllers and views.

#277
This commit is contained in:
N. Taylor Mullen 2014-05-01 12:30:56 -07:00
parent 31cdc09647
commit 6dc6ba6d37
2 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@
// permissions and limitations under the License.
using System;
using System.Security.Principal;
using System.Text;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Mvc.Core;
@ -54,6 +55,18 @@ namespace Microsoft.AspNet.Mvc
public IActionResultHelper Result { get; private set; }
public IUrlHelper Url { get; set; }
public IPrincipal User
{
get
{
if (Context == null)
{
return null;
}
return Context.User;
}
}
public ViewDataDictionary ViewData { get; set; }
@ -155,7 +168,7 @@ namespace Microsoft.AspNet.Mvc
public RedirectToActionResult RedirectToAction(string actionName, string controllerName,
object routeValues)
{
return new RedirectToActionResult(Url, actionName, controllerName,
return new RedirectToActionResult(Url, actionName, controllerName,
TypeHelper.ObjectToDictionary(routeValues));
}
@ -177,7 +190,7 @@ namespace Microsoft.AspNet.Mvc
public RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName,
object routeValues)
{
return new RedirectToActionResult(Url, actionName, controllerName,
return new RedirectToActionResult(Url, actionName, controllerName,
TypeHelper.ObjectToDictionary(routeValues), permanent: true);
}

View File

@ -22,6 +22,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.DependencyInjection;
@ -44,6 +45,19 @@ namespace Microsoft.AspNet.Mvc.Razor
public IUrlHelper Url { get; private set; }
public virtual IPrincipal User
{
get
{
if (Context == null || Context.HttpContext == null)
{
return null;
}
return Context.HttpContext.User;
}
}
public dynamic ViewBag
{
get