views:

20

answers:

1

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>();
        }
}
+2  A: 

I would honestly start by looking at the data differences in the databases, it sounds dumb but maybe the roles don't actually exist or ApplicationIds are different. If necessary run SQL Profiler against the app using the different databases and verify the queries are the same and the data returned is the same.

INinjaAndy