2013-01-07 51 views
1

我有一個使用Windows身份驗證的asp.net/c#應用程序。我試圖根據AD用戶所屬的權限來控制權限,但似乎無法通過web.config使其工作。Active Directory成員資格提供程序 - AD組/ Web.Config不起作用

我也是在代碼中添加一些代碼後面,它甚至舉止怪異:

if (Roles.IsUserInRole("STP Admin")) 
{ 
    int j = 1; 
} 

if (User.IsInRole(@"DOMAINNAME\STP Admin")) 
{ 
    int i = 1; 
} 

第一,如果塊不工作,但第二個呢。所以我相信這告訴我應用程序可以/正在與AD進行通信。

這裏是我的web.config這正是我想要的代碼去和它不工作的授予權限。即使我處於這些羣體中,它也會拒絕我訪問這些路徑,經過上面的代碼證明。

<?xml version="1.0"?> 

<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <configSections> 

    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </configSections> 
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> 
    <listeners> 
     <add databaseInstanceName="STPDB" writeLogStoredProcName="WriteAuditLog" addCategoryStoredProcName="AddAuditCategory" formatter="Custom Audit Database Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Database Trace Listener"/> 
     <add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Formatted EventLog TraceListener"/> 
    </listeners> 
    <formatters> 
     <add template="{dictionary({key} - {value})}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Custom Audit Database Formatter"/> 
     <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="Audit"> 
     <listeners> 
      <add name="Database Trace Listener"/> 
     </listeners> 
     </add> 
     <add switchValue="All" name="General"> 
     <listeners> 
      <add name="Formatted EventLog TraceListener"/> 
     </listeners> 
     </add> 
    </categorySources> 
    <specialSources> 
     <allEvents switchValue="All" name="All Events"/> 
     <notProcessed switchValue="All" name="Unprocessed Category"> 
     <listeners> 
      <add name="Formatted EventLog TraceListener"/> 
     </listeners> 
     </notProcessed> 
     <errors switchValue="All" name="Logging Errors &amp; Warnings"> 
     <listeners> 
      <add name="Formatted EventLog TraceListener"/> 
     </listeners> 
     </errors> 
    </specialSources> 
    </loggingConfiguration> 
    <connectionStrings> 
    <add name="STPDB" connectionString="Data Source=server\;Initial Catalog=DB;user id=usr;pwd=pass;Integrated Security=False" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 
    <appSettings> 
    <add key="FromEmailAddress" value="[email protected]"/> 
    <add key="TrainingWarning" value="*Note: Training not being recorded for Medical, ..."/> 
    <add key="PrivacyMessage" value="This Information System Is Subject To The Privacy Act Of 1974"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <securityPolicy> 
     <trustLevel name="Full" policyFile="internal"/> 
    </securityPolicy> 
    <authentication mode="Windows"/> 
    <authorization> 
     <deny users="?"/> 
     <allow roles="DOMAIN\STP Training"/> 
     <allow roles="DOMAIN\STP Personnel"/> 
     <allow roles="DOMAIN\STP Admin"/> 
     <allow users="*"/> 
    </authorization> 
    <identity impersonate="true"/> 

    <membership defaultProvider="AspNetActiveDirectoryMembershipProvider"> 
     <providers> 
     <clear/> 
     <add name="AspNetActiveDirectoryMembershipProvider" 
      type="System.Web.Security.ActiveDirectoryMembershipProvider, 
       System.Web, Version=4.0.0.0, Culture=neutral, 
       PublicKeyToken=b03f5f7f11d50a3a" /> 
     </providers> 
    </membership> 

    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"> 
     <providers> 
     <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider"/> 
     </providers> 
    </roleManager> 

    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true"> 
     <providers> 
     <add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true"/> 
     </providers> 
    </siteMap>  

    <profile> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> 
     </providers> 
    </profile> 

    <!-- 
      The <customErrors> section enables configuration 
      of what to do if/when an unhandled error occurs 
      during the execution of a request. Specifically, 
      it enables developers to configure html error pages 
      to be displayed in place of a error stack trace. 
     --> 

    <customErrors mode="RemoteOnly" redirectMode="ResponseRewrite" defaultRedirect="~/ErrorPage.aspx"> 
    </customErrors> 
    </system.web> 

    <location path="\TrainingSec"> 
    <system.web> 
     <authorization> 
     <allow roles="STP Training"/> 
     <allow roles="STP Admin"/> 
     <deny users="*"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="\Manage"> 
    <system.web> 
     <authorization> 
     <allow roles="STP Training"/> 
     <deny users="*"/> 
     <allow roles="Sentry Admin"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="\Admin"> 
    <system.web> 
     <authorization> 
     <allow roles="STP Admin"/> 
     <deny users="*"/> 
     </authorization> 
    </system.web>  
    </location> 

    <system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network" from="[email protected]"> 
     <network defaultCredentials="false" host="11.111.11.11" port="25"/> 
     </smtp> 
    </mailSettings> 
    </system.net> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <defaultDocument> 
     <files> 
     <clear /> 
     <add value="Dashboard.aspx"/> 
     </files> 
    </defaultDocument> 
    </system.webServer> 
</configuration> 

回答

1

你似乎忘記了域部分:

<location path="\TrainingSec"> 
    <system.web> 
     <authorization> 
     <allow roles="DOMAIN\STP Training"/> 
     <allow roles="DOMAIN\STP Admin"/> 
     <deny users="*"/> 
     </authorization> 
    </system.web> 
    </location> 
+0

哇,謝謝大家似乎都做到了。一個簡單的問題,如果你可以回答;何時需要擁有LDAP連接字符串?爲什麼我不需要在我的web.config中 –

相關問題