Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Access to dropdownlist items based on the User's Active Directory Group
    text
    copied!<p>Background: I have a webForm app that registers a user in the database based on the information provided with a web service, auto-generates a random password and username, and e-mails the user a link to take an application based on the marketing company selected.</p> <p>Questions: </p> <ul> <li>How do I get only the currently logged in user's groups to show up under the MarketingCo_DropDownList </li> </ul> <p>Each user allowed access to the system will have membership in at least one of the marketing groups as defined by the web.config. For example, a user that is currently logged in and belongs to the BIG group under location "alg\ACOMP_user_BIG", will only be able to see BIG in the Marketing Company drop down list. A user that is currently logged in and belongs to the NIS group located under "alg\ACOMP_user_NIS" will only be able to see NIS in the Marketing Company drop down list.</p> <p>Here's a screenshot of the front end: <img src="https://i.stack.imgur.com/iP19n.jpg" alt="web app screenshot"></p> <p>Here's my best guess (located under Private Sub GetMarketingCompanies() method in default.aspx.vb):</p> <pre><code> If InStr(WindowsIdentity.GetCurrent().Groups = "AMG", item.MarketingCompanyShort = "AMG", CompareMethod.Text) Then marketingCo.Items.Add(String.Format("{0} | {1}", item.MarketingCompanyShort, item.MarketingCompanyName)) For Each item In ac1 marketingCo.Items.Add(String.Format("{0} | {1}", item.MarketingCompanyShort, item.MarketingCompanyName)) Next Catch ex As Exception MsgBox(ex.Message) End Try </code></pre> <p>I've been going off the code from <a href="http://www.wrox.com/WileyCDA/Section/ASP-NET-3-5-Windows-Based-Authentication.id-310905.html" rel="nofollow noreferrer">Wrox's Windows Authentication Tutorial</a> but it's not thorough enough for what I'm trying to do. </p> <p>Web.config file (pertinent code displayed only): </p> <pre><code> &lt;authentication mode="Windows"/&gt; &lt;authorization&gt; &lt;allow users="alg\bmccarthy, alg\phoward" /&gt; &lt;allow roles="alg\ACOMP_user_Admin" /&gt; &lt;allow roles="alg\ACOMP_user_AMG" /&gt; &lt;allow roles="alg\ACOMP_user_BIG" /&gt; &lt;allow roles="alg\ACOMP_user_NIS" /&gt; &lt;allow roles="alg\ACOMP_user_GLA" /&gt; &lt;allow roles="alg\ACOMP_user_PIP" /&gt; &lt;allow roles="alg\ACOMP_user_PSM" /&gt; &lt;allow roles="alg\ACOMP_user_PAM" /&gt; &lt;allow roles="alg\ACOMP_user_ANN" /&gt; &lt;allow roles="alg\ACOMP_user_AAM" /&gt; &lt;allow roles="alg\ACOMP_user_MWM" /&gt; &lt;allow roles="alg\ACOMP_user_GIM" /&gt; &lt;deny users="*" /&gt; &lt;/authorization&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;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"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://172.17.1.40/aCompService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAcompService" contract="aComp_ServiceReference.IAcompService" name="BasicHttpBinding_IAcompService" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; </code></pre> <p>default.aspx.vb code w/ the GetMarketingCompanies() and Page_Load() Methods where the application retrieves MarketingCompanies from the webservice and loads it into the dropdownlist through an array: </p> <pre><code>Private Sub GetMarketingCompanies() Try Dim ac1 As Array ac1 = proxy.GetMarketingCompanyNames("acompUser", "acompPass!") ' If InStr(WindowsIdentity.GetCurrent().Groups = "AMG", item.MarketingCompanyShort = "AMG", CompareMethod.Text) Then ' marketingCo.Items.Add(String.Format("{0} | {1}", item.MarketingCompanyShort, item.MarketingCompanyName)) ' if current user role="alg\ACOMP_user_BIG" display BIG MarketingCo.Item ' ' if current user role="alg\ACOMP_user_NIS" display NIS MarketingCo.Item ' ' if current user role="alg\ACOMP_user_GLA" display GLA MarketingCo.Item ' ' if current user role="alg\ACOMP_user_PIP" display PIP MarketingCo.Item ' ' if current user role="alg\ACOMP_user_PSM" display PSM MarketingCo.Item ' ' if current user role="alg\ACOMP_user_PAM" display PAM MarketingCo.Item ' ' if current user role="alg\ACOMP_user_ANN" display ANN MarketingCo.Item ' ' if current user role="alg\ACOMP_user_AAM" display AAM MarketingCo.Item ' ' if current user role="alg\ACOMP_user_MWM" display MWM MarketingCo.Item ' ' if current user role="alg\ACOMP_user_GIM" display GIM MarketingCo.Item ' ' if current user = alg\ACOMP_user_Admin display all marketing companies in drop down list ' For Each item In ac1 marketingCo.Items.Add(String.Format("{0} | {1}", item.MarketingCompanyShort, item.MarketingCompanyName)) Next Catch ex As Exception MsgBox(ex.Message) End Try 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 &gt; 0 Then GetCarriers() GetMarketingCompanies() End If End Sub </code></pre> <p>Default.aspx code where the marketingCo drop down list is defined: </p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td class="style3"&gt; Marketing Co (auto-populated): &lt;/td&gt; &lt;td bgcolor="#ffffff" class="style8"&gt; &lt;asp:DropDownList ID="marketingCo" runat="server" Height="23px" Width="250px"&gt; &lt;/asp:DropDownList&gt; &lt;/td&gt; &lt;/tr&gt; &lt;td bgcolor="#ffffff" class="style6"&gt; &lt;asp:Button ID="Send_Button" runat="server" Text="Send Invitation" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>The Web service returns an Array of Strings w/ MarketingCompanyShort and MarketingCompanyName that are added as items to the drop down list Web Service XSD File Code: </p> <pre><code>&lt;xs:element name="ArrayOfMarketingCompany" type="tns:ArrayOfMarketingCompany" nillable="true"/&gt; &lt;xs:complexType name="MarketingCompany"&gt; &lt;xs:sequence&gt; &lt;xs:element name="MarketingCompanyId" type="xs:int" minOccurs="0"/&gt; &lt;xs:element name="MarketingCompanyName" type="xs:string" nillable="true" minOccurs="0"/&gt; &lt;xs:element name="MarketingCompanyShort" type="xs:string" nillable="true" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>Thanks for looking! </p> <p>If you have any helpful links or suggestions, I'll give you an up-vote! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload