I have created a custom identity, principal and membership provider and accessing them through a UserContext class (all sitting in App_code):
public static class UserContext
{
public static CustomPrincipal User
{
get
{
return (CustomPrincipal)HttpContext.Current.User;
}
}
public static CustomIdentity Identity
{
get
{
return (CustomIdentity)HttpContext.Current.User.Identity;
}
}
}
From a controller class, I can do:
string userName = UserContext.Identity.Name;
However when doing the following from a view:
@Html.Encode(UserContext.Identity.Name)
I get the following error at run time:
The type 'Website.Infrastructure.UserContext' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\533b7079\25c5a39c\assembly\dl3\13397e32\308e247b_c8efce01\Website.DLL' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\533b7079\25c5a39c\App_Code.-ze7s5wd.dll'
I have cleared out the temp/cache IISExpress folders, etc., ensured that I'm using System.Web v4.0.0, and have tried with adding the using [namespace]
at the top of the shared layout view and in the relevant view's Web.config section.
Looking at the view, I'm seeing a compile error (suggestion?) under
UserContext
The type 'xxx' exists both in '[website root]' and 'App_Code' from a MVC view
Suggestions?