Print Page | Close Window

_entityManager.Principal always returns Guest

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2072
Printed Date: 27-Apr-2025 at 1:38pm


Topic: _entityManager.Principal always returns Guest
Posted By: madone
Subject: _entityManager.Principal always returns Guest
Date Posted: 18-Aug-2010 at 5:28am
I am trying to setup my applicaton to run with Windows authentication.  Why does it always return "Guest" as the user name.  I know it's me, but, I can't figure it out.  Below is my code from mainPage.  The web config has  <authentication mode="Windows" />.
 
 
public partial class MainPage : UserControl
    {
        #region ctor & load
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            CreateEntityManager();
            Reset();
            Login();
        }
        private void CreateEntityManager()
        {
            // create the entity manager but do not connect yet.
            _entityManager = new CollectionsEntities(false);
        }
        #endregion ctor & load
        #region login
        private void Login()
        {
            var mgr = CollectionsEntities.DefaultManager;
            mgr.LoginAsync(null, LoginCompleted, null);
        }
        private void LoginCompleted(LoginOperation args)
        {
            if (args.HasError)
            {
                txtMessages.Text = args.Error.Message + "  Web Config is probably set wrong";
                return;
            }
            UserBase user = _entityManager.Principal as UserBase;
            txtLoggedInAs.Text = user.Name;
// The user.Name is Guest # (where the # increases each time I refresh.
            if (!user.IsAuthenticated)
            {
                txtMessages.Text = " Not authenticated.";
            }
        }
        #endregion login



Replies:
Posted By: madone
Date Posted: 18-Aug-2010 at 10:17am
I found the problem.
 
My web.config had the aspNetCompatibilityEnabled="false".  Now that I changed it to
 
<!-- Set this to true to allow use of ASP.NET security features. -->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

All is working as expected.



Posted By: ting
Date Posted: 19-Aug-2010 at 5:34pm
Cool.  Thanks for letting us know!



Print Page | Close Window