2012-03-09 6 views
1

私は自分のウェブサイトにFormAuthenticationを設定しました。web.configの<location>の順番は重要ですか?

ログインページとそのリソース(js、css、images)への匿名アクセスを許可します。

私はweb.configに追加しました。そこに秩序が関係するのだろうか?

<configuration> 
    <configSections> 
    <section name="hibernate-configuration" 
      type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /> 
    <section name="log4net" 
      type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
    </configSections> 
    <appSettings> 
    <add key="webpages:Version" value="1.0.0.0" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <location path="~/Authentication.htm"> 
    <system.web> 
     <authorization> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <location path="~/Resources"> 
    <system.web> 
     <authorization> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <location path="~/js"> 
    <system.web> 
     <authorization> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <location path="~/Images"> 
    <system.web> 
     <authorization> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <location path="~/Controllers"> 
    <system.web> 
     <authorization> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
    </location> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     ..... 
     </assemblies> 
    </compilation> 
    <authentication mode="Forms"> 
     <forms name="Login" loginUrl="~/Authentication.htm" 
      protection="All" path="/" timeout="30" /> 
    </authentication> 
    <authorization> 
     <deny users ="?" /> 
     <allow users = "*" /> 
    </authorization> 

なぜ私はまだ追加されたパスに対して認証エラーが発生しますか?

Authentication.htm?ReturnUrl=%2fResources%2fScripts%2fjquery-1.7.1.min.js:1Uncaught SyntaxError: Unexpected token < 

Authentication.htm?ReturnUrl=%2fjs%2fCommon.js:1Uncaught SyntaxError: Unexpected token < 

Authentication.htm?ReturnUrl=%2fjs%2fAuthentication.js:1Uncaught SyntaxError: Unexpected token < 

答えて

2

あなたのルート設定は、すべての認証されていないユーザー(?を)拒否し、あなたの場所の設定は、すべてのユーザー(*を)拒否する。

あなたはおそらくこれを行うためのもの:

<!-- web application root settings --> 
<authorization> 
    <deny users ="?" /> 
</authorization> 

<!-- login and static resources --> 
<location path="~/Images"> 
    <system.web> 
    <authorization> 
     <allow users="*" /> 
    </authorization> 
    </system.web> 
</location> 
+0

それは役に立たなかった。権限のないユーザーがログインページ(js、css、images)に関連するすべてのコンテンツを取得できるようにします。あなたの設定を書いた後、私はまだImgaesとスクリプトを手に入れません。 –

+0

Visual Studioから実行する前に見たことがありますが、IISにデプロイしても機能します。 – jrummell

+0

問題は '〜'でした。私はそれがより明確であると思ったが、それは相対的な経路に失敗した –

0

注文は、あなたが重複した要素を持っている場合、最後の要素が考慮されることでも問題ありません。

関連する問題