2013-03-01 100 views
1

試圖限制匿名用戶登錄login.aspx,register.aspx和Site.css文件並進行身份驗證以訪問整個站點。 當前anonymous可以訪問login.aspx和Site.css,因爲樣式顯示正確。但是,當我點擊register.aspx鏈接時,我被重定向到login.aspx頁面。有權訪問register.aspx但被重定向到登錄頁面的匿名用戶

在web根目錄下我的web.config。目錄結構中沒有其他web.configs。我不知道我是否應該尋找其他地方(我知道WSAT有時可以保持規則,但不知道是否被根Web.config取代)。

只是想登錄和註冊文件引用母版頁,這是否也需要明確的授權?雖然不能解釋爲什麼登錄工作的匿名,但註冊不。

感謝您的幫助!安東尼。

<?xml version="1.0"?> 

<configuration> 
    <connectionStrings> 
    <add name="************" 
     connectionString="Data Source=**********; Initial Catalog=************; Integrated Security=SSPI; Persist Security Info=False; Trusted_Connection=Yes" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <location path="Register.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="Login.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="Site.css"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <authentication mode="Forms"> 
     <forms loginUrl="~/Website/Login.aspx" timeout="2880" /> 
    </authentication> 

    <authorization> 
     <deny users="?"/> 
    </authorization> 

    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" 
      enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="***********" /> 
     </providers> 
    </membership> 

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

    <roleManager enabled="false"> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="***********" applicationName="/" /> 
     <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> 
     </providers> 
    </roleManager> 
    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 
+0

入住提琴手或'Network'選項卡瀏覽器的開發工具,這要求!返回401代碼 – 2013-03-01 09:14:53

回答

-1

嘗試更改包含〜/網站的路徑,與您的表單身份驗證登錄位置相同。您不需要默認指定的登錄頁面,它允許訪問,因爲它是您的formsauthentication設置中的LoginUrl。

<location path="~/Website/Register.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="~/Website/Login.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 
+0

謝謝我試過這個,但它沒有區別,而且,因爲我然後切換回以前的代碼,我的樣式不再通過 - 不知道是否有發展Web服務器或鉻瀏覽器或asp的緩存問題。 net有時緩存web.configs? – user2122755 2013-03-01 09:40:59

+0

什麼是您在瀏覽器中導航到Reg的確切URL ister頁面和登錄頁面,包括http://? – WDuffy 2013-03-01 09:52:11

+0

http:// localhost:4842/Website/Login.aspx http:// localhost:4842/Website/Register.aspx但是當我點擊Register.aspx鏈接時,我得到這個返回的地址欄:http:// localhost :4842/Website/Login.aspx?ReturnUrl =%2fWebsite%2fRegister.aspx – user2122755 2013-03-01 10:05:11

0

此代碼將只允許匿名用戶: (注意添加否認節點之後的允許

<location path="Register.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
相關問題