I have a roleprovider set up as follows using a DataContext. On my View, I have the following user Control...
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
if (Request.IsAuthenticated) {
%>
Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
<%= Html.ActionLink("Logout", "Logout", "Membership") %> | (
<%
var roles = System.Web.Security.Roles.GetRolesForUser(Page.User.Identity.Name);
foreach (string role in roles)
Html.Encode(role);
%>
)
Now if I run this on my local machine, it works fine. Mind you, connected to the same database as my remote box. It logs in, and shows the roles the member is a part of.
if I run on the remote box , with the SAME database, it will login and show the member name - BUT... it doesn't render the roles. Any ideas why this might be happening? My Role Provider is drawn out below.
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Providers
{
public partial class RoleProvider : System.Web.Security.RoleProvider
{
private readonly Models.Contexts.DatabaseDataContext dataContext;
protected Models.Contexts.DatabaseDataContext DataContext
{
get { return dataContext; }
}
public RoleProvider()
: base()
{
if (dataContext == null)
dataContext = new DataContextProvider().GetDataContext<Models.Contexts.DatabaseDataContext>("contextProvider");
}
public RoleProvider(IDataContextProvider dataContextProvider)
: this()
{
dataContext = dataContextProvider.GetDataContext<Models.Contexts.DatabaseDataContext>("contextProvider");
}
public override string[] GetRolesForUser(string email)
{
DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
var member = (
from m in DataContext.Users
where m.Email == email
select m).Single();
List<string> roleList = new List<string>();
foreach (Models.Group group in member.Groups)
roleList.Add(group.Role.RoleName);
return roleList.ToArray<string>();
}
}