2012-03-15 23 views
1

サンプルコード:IISエラー「型のオブジェクトをキャストすることができません 『System.DirectoryServices.AccountManagement.GroupPrincipal』」

staffName.Text = UserPrincipal.Current.Name; 

私はVS2010からIISへの私のプロジェクトを公開するときこんにちは、私はこのエラーを持っています。誰も私を助けても、私はコードと参照を削除しようとしましたが、私はまだこのエラー(これは奇妙です)を取得します。

エラー:

Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'. 

スタックトレース:

[InvalidCastException: Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.] 
    System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +57 
    System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +218 
    Appraisal.Staffmain.Page_Load(Object sender, EventArgs e) +121 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 
    System.Web.UI.Control.OnLoad(EventArgs e) +91 
    System.Web.UI.Control.LoadRecursive() +74 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 

答えて

0

私は、これはHttpContext.Current.User.Identity.Name属性を使用して切り替えます。

staffName.Text = HttpContext.Current.User.Identity.Name; 

これにより、Webアプリケーションの現在のユーザーが表示されます。

+0

nice!実行することができますが、何も表示しません。 ( ""のように) –

+0

現在のユーザーを認証方法で設定する必要があります。匿名でログインしている場合、私はそれが空白になると信じています。 – tsells

+0

私は上記の空白を取得します。 – Si8

関連する問題