0

背景: Web サービスで提供される情報に基づいてデータベースにユーザーを登録し、ランダムなパスワードとユーザー名を自動生成し、マーケティング会社に基づいてアプリケーションを取得するためのリンクをユーザーに電子メールで送信する webForm アプリがあります。選択されました。

質問:

  • 現在ログインしているユーザー名を MarketerName_TextBox フィールドに入力するにはどうすればよいですか (それは User.Identity.Name で、その行を aspx.vb の末尾または aspx の末尾に追加しますか?)

フロントエンドのスクリーンショットは次のとおりです。 ウェブアプリのスクリーンショット

私はWrox の Windows Authentication Tutorial のコードから離れてきましたが、私がやろうとしていることには十分ではありません。

web.config ファイル:

web.config ファイル (関連するコードのみ表示):

 <authentication mode="Windows"/>
   <authorization>

    <allow users="alg\bmccarthy, alg\phoward" />               
    <allow roles="alg\ACOMP_user_Admin" />
    <allow roles="alg\ACOMP_user_AMG" />
    <allow roles="alg\ACOMP_user_BIG" />
    <allow roles="alg\ACOMP_user_NIS" />
    <allow roles="alg\ACOMP_user_GLA" />
    <allow roles="alg\ACOMP_user_PIP" />
    <allow roles="alg\ACOMP_user_PSM" />
    <allow roles="alg\ACOMP_user_PAM" />
    <allow roles="alg\ACOMP_user_ANN" />
    <allow roles="alg\ACOMP_user_AAM" />
    <allow roles="alg\ACOMP_user_MWM" /> 
    <allow roles="alg\ACOMP_user_GIM" />
    <deny users="*" />        
</authorization> 

   <bindings>
   <basicHttpBinding>
    <binding name="BasicHttpBinding_IAcompService" 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://172.17.1.40/aCompService.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IAcompService" contract="aComp_ServiceReference.IAcompService"
    name="BasicHttpBinding_IAcompService" />
  </client>
 </system.serviceModel>

txtMarketerName_TextChanged() および Page_Load() メソッドを使用した default.aspx.vb コード:

Private Sub GetCarriers()
    Dim ac1 As Array
    ac1 = proxy.GetCarrierNames("test", "test")
    For Each item In ac1
        lbCarriers.Items.Add(String.Format("{0} | {1} | {2}", item.CarrierID, item.CarrierNameLong, item.CarrierNameShort))
    Next
End Sub

Private Sub txtMarketerName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMarketerName.TextChanged

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, Me.Load, Me.Load

    If Not lbCarriers.Items.Count > 0 Then
        GetCarriers()
        GetMarketingCompanies()
    End If

End Sub

マーケティング担当者名のテキスト ボックス フィールドが表示される default.aspx コード:

<table id="Table1" border="0" cellpadding="6" cellspacing="0" align=center>
    <tr>
        <td class="style1">
            My Name (auto-populated Current Logged In User's Name): </td>
        <td bgcolor="#ffffff" class="style6">
            <asp:TextBox ID="txtMarketerName" runat="server" Width="250px">    
        </asp:TextBox>
        </td>
        <td bgcolor="#ffffff" class="style2">
            <asp:RequiredFieldValidator ID="regValMarketerName" runat="server"
ControlToValidate="txtMarketerName" ErrorMessage="Marketer Name is required" Text="*"
ValidationGroup="Valtxt">
        </asp:RequiredFieldValidator>
        </td>
    </tr>

ご覧いただきありがとうございます。

役立つリンクや提案があれば、賛成票を投じます!

4

2 に答える 2

1

次のように、Page_Load evemtのコードビハインドで、ラベルまたはテキストボックスの値を現在のWindowsユーザーのユーザー名に設定できます。

txtUsername.Text = User.Identity.Name;

または、次のようにマークアップで行うことができます。

<asp:Label runat="server" ID="lblUsername"><%=User.Identity.Name %></asp:Label>
于 2011-04-20T13:43:02.037 に答える
0

これが、deafult.aspx.vb コード ビハインド ページで最終的に使用したものです。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, Me.Load, Me.Load

    If Not lbCarriers.Items.Count > 0 Then
        txtMarketerName.Text = WindowsIdentity.GetCurrent.Name
        GetCarriers()
        GetMarketingCompanies()
    End If

End Sub

WindowsIdentity.GetCurrent().Name と User.Identity.Name

WindowsIdentity.GetCurrent() メソッドは、スレッドを実行している ID を表す WindowsIdentity インスタンスを返します。User.Identity オブジェクトは、IIS から渡された ID を表します。IIS がユーザーにページへの匿名アクセスを許可する場合、User.Identity.Name プロパティは空の文字列を返します。それ以外の場合は、IIS によって認証されたユーザーのアカウント名が返されます。

User.Identity.Name - 戻り値: my_domain\jdoe

System.Environment.UserName 戻り値: jdoe

于 2011-04-20T18:19:15.977 に答える