2011-08-02 10 views
0

ローカルIISでホストされているASP.NETページにアクセスしているクライアントのWindowsユーザ名を取得しようとしています。私は、クライアントのWindowsユーザ名を返すASP.NETページ内のWCFサービスを呼び出しています。私はについて、それらのほとんどはWCFを使用してクライアントのWindowsユーザ名を取得しようとしています

  1. OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
  2. HttpContext.Current.User.Identity.Name
  3. HttpContext.Current.Userことを示唆しているように多くの記事に出くわしました。 Identity.Name

私が直面している問題は、 "1"は常にNullを返すことです。 "2"と "3"は常にローカルユーザー名を返し、要求ユーザーの名前は返しません。 ASP.NETとWCFサービスの両方のweb.configsに何かがありませんか?

IISプロパティ:Windows統合認証が有効です。

ここにコードがあります。

WCF

public string GetWindowsUser()  
{ 
    string temp = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name; 
    string temp1 = HttpContext.Current.User.Identity.Name; 
    string temp2 = HttpContext.Current.User.Identity.Name; 
    return "Temp: "+temp+" \nTemp1: "+temp1+" \nTemp2: "+temp2; 
} 

web.configファイル

<system.web> 
    <compilation debug="false" targetFramework="4.0"/> 
</system.web> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
        <message clientCredentialType="UserName" algorithmSuite="Default"/> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:4772/Services.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WindowsAuthServices.IService1" name="BasicHttpBinding_IService1"/> 
    </client> 
</system.serviceModel> 

ASP.NETページ:

protected void Page_Load(object sender, EventArgs e) 
{ 
    WindowsAuthServices.Service1Client client = new WindowsAuthServices.Service1Client(); 
    lblWelcome.Text = client.GetWindowsUser(); 
} 

のWeb.Config

<system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
</system.web> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
        <message clientCredentialType="UserName" algorithmSuite="Default"/> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:4772/Services.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WindowsAuthServices.IService1" name="BasicHttpBinding_IService1"/> 
    </client> 
</system.serviceModel> 
+0

あなたがやろうとしていることを止めて教えてください。 –

+0

当社の企業は、会社のデバイス(ラップトップ)を使用しているサイトだけを開設したいと考えています。そのため、SharePointサイトでWindows認証を使用し、ユーザー名とパスワードを要求しないようにします。ウィンドウのユーザー名が承認されたユーザーの一覧にあるユーザー名と一致する場合は、別の認証ページにリダイレクトされます。第1部を終わらせることは問題でした。 – Santosh

答えて

0

チェックしてくださいね。他のユーザーがIPを使用してローカルIISにアクセスしようとすると、ローカルIISはイントラネット要求ではなくイントラネット要求であるとみなし、Windows認証以降はイントラネット要求でのみ機能します。これを解決するために私はドメインサーバーの1つで自分のWebサイトをホストしなければなりませんでした。ドメインサーバーはすでに、そのドメインのユーザーのみがアクセスできるように設定されていたので、Windowsログイン情報が表示されます。そして私の不幸は終わります。

1

あなたのコールがASP.Netワーカープロセスは、(偽装と呼ばれている)のページを要求しているユーザーのIDで実行されていないその下のアイデンティティに代わって行われているためです。 http://geekswithblogs.net/robz/archive/2007/10/03/wcf-impersonation---specifying-windows-authentication-credentials-on-the-service.aspx

1)(Iは、認証要素の下にそれを置く次のマークアップを使用して偽装を設定しているために必要なASP.NETクライアントのweb.configファイルから

)に示すよう:

 
<authentication mode="Windows"/> 
<identity impersonate="true"/> 

2 )サービスの動作は、アクセス許可と呼び出し元を偽装するためにWindowsを使用するように構成する必要がありました。

+0

どうすればこの問題を解決できますか?私に教えてもらえますか?私はWCFの初心者です。あなたの助けに感謝します。ありがとう。 – Santosh

+0

したがって、(観測だけでなく)明白な答えは偽装を有効にすることです。ここをクリックしてください:http://geekswithblogs.net/manesh/archive/2009/04/23/setting-up-wcf-to-impersonate-client-credentials.aspx、http://geekswithblogs.net/robz/archive /2007/10/03/wcf-impersonation---specifying-windows-authentication-credentials-on-the-service.aspx –

+0

あなたが述べた変更を試しました。それはうまくいかない。それはまだ同じです。 :( – Santosh

0

当社の企業は、そのサイトは、会社 デバイス(ラップトップ)を使用したものだけをオープンしたいと考えています。したがって、彼らは共有サイトがWindows 認証を使用し、ユーザー名とパスワードを要求しないようにします。 windowsのユーザー名が承認されたユーザーの一覧にあるユーザー名と一致する場合は、 を開くか、別の認証ページにリダイレクトする必要があります。 の第1部が問題になっています。

Windowsのドメインに接続し、統合セキュリティを使用し、Sharepointで正しいセキュリティグループを設定するだけで、ラップトップが必要です。

あなたの説明はセキュリティではなく、決してうまくいかないでしょう。

0

は、あなたが/実装あなたが委任に対してWCFを設定する必要がある場合identity delegation.ためにあなたのウェブサイトを構成する必要があるように、私は最終的に解決策を見つけたthis MSDN article.

関連する問題