2011-06-10 93 views
1

我似乎無法讓Windows身份驗證在Silverlight業務應用程序中工作。Silverlight業務應用程序Windows身份驗證

我已經作出所需的改變見下文

更改爲Windows身份驗證中的App.xaml

public App() 
    { 
     InitializeComponent(); 

     // Create a WebContext and add it to the ApplicationLifetimeObjects 
     // collection. This will then be available as WebContext.Current. 
     WebContext webContext = new WebContext(); 
     //webContext.Authentication = new FormsAuthentication(); 
     webContext.Authentication = new WindowsAuthentication(); 
     this.ApplicationLifetimeObjects.Add(webContext); 
    } 

在web.config中更改爲Windows身份驗證

<authentication mode="Windows"/> 

<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/> 

我把一個斷點在Application_UserLoaded事件但沒有任何反應: -

private void Application_UserLoaded(LoadUserOperation operation) 
    { 
     foreach (var r in WebContext.Current.User.Roles) 
     { 
      //do something 
     } 
    } 

任何人都可以提出什麼問題。我根本沒有對該項目做任何其他改變。

+0

您是不是想要使用Active Directory中的組或者您打算自己管理組成員身份? – 2011-06-12 15:33:44

+0

嘗試禁用web.config文件中的匿名用戶。但是當我需要知道用戶名時,我調用了一個返回它的wcf服務方法。 – vorrtex 2011-06-12 19:05:04

回答

0

這在我以前也發生過。事實證明,Silverlight調試沒有在Web項目的屬性中啓用。右鍵點擊.Web項目並點擊屬性。接下來點擊Web選項卡並在底部確保選中Silverlight複選框。

0

您必須具有該線路Application_Startup

WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null); 

使用Windows身份驗證時,這將自動驗證用戶。

相關問題