【问题标题】:styles not accessible before and after authenticated (ASP.NET forms authentication)在经过身份验证之前和之后无法访问的样式(ASP.NET 表单身份验证)
【发布时间】:2011-05-08 02:03:15
【问题描述】:

我刚刚构建了一个带有表单身份验证的应用程序。我无法在应用程序中看到我的样式(在成功登录后在 Login.aspx 或页面上进行身份验证之前)。当应用程序使用 Windows 身份验证时,它们曾经是可访问的。

我阅读了另一个论坛,上面说您必须在验证之前授予对包含 css 的 App_Themes 文件夹的访问权限,但请再次阅读以上内容(验证后我也看不到它们)。这在使用 Windows 身份验证之前有效。我引入了另一个菜单库,所以你现在会看到 3 个部分。

我使用的是 Windows 7。哦,我右键单击了包含我的网站文件的根文件夹。我在 IIS 7 中添加了 IIS_IUSRS 组和 IIS APPPOOL[APP POOL NAME] 的权限。我将所有权限都授予了。此外,我启用了基本身份验证,并在我的站点中启用了表单身份验证。其余被禁用。

感谢堆栈溢出天才!!

===========================

web.config

Visual Studio 中的 Asp.Net 配置选项。 设置和 cmets 的完整列表可以在 machine.config.cmets 通常位于 \Windows\Microsoft.Net\Framework\v2.x\Config -->
<compilation debug="true">
  <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </assemblies>
</compilation>
<!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->

<!--<authentication mode="Forms">
  <forms cookieless="UseCookies" slidingExpiration="true"
         protection="All" timeout="60" loginUrl="~/Login.aspx">
  </forms>
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*"/>
</authorization>-->

  <authentication mode="Forms">
      <forms name="WANTA-AUTHENTICATE"
             loginUrl="Login.aspx"
             protection="All"
             timeout="5"
             path="/">
          <credentials passwordFormat="MD5" />
      </forms>
  </authentication>
  <authorization>
      <allow users="*"/>
      <deny users="?" />
  </authorization>      



<customErrors mode="Off" defaultRedirect="Default.aspx">

</customErrors>

<pages>
  <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </controls>
</pages>
<httpHandlers>
  <remove verb="*" path="*.asmx"/>
  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

<!--  SESSION STATE SETTINGS
      By default ASP.NET uses cookies to identify which requests belong to a particular session. 
      If cookies are not available, a session can be tracked by adding a session identifier to the URL. 
      To disable cookies, set sessionState cookieless="true".
-->
<sessionState mode="InProc" timeout="55" />

<system.serviceModel>

<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
  <baseAddressPrefixFilters>
    <add prefix="http://localhost/" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>-->

<behaviors>
  <endpointBehaviors>
    <behavior name="AspNetAjaxBehavior">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>

 <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
 </serviceBehaviors>
</behaviors>

<services>       
    <service name="Wanta.Toolkit.WantaService" behaviorConfiguration="ServiceBehavior">            
        <endpoint behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding" contract="Wanta.Toolkit.WantaService" />            
    </service>        
</services>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

===================

登录.aspx.cs

protected void Logon_Click(object sender, EventArgs e)
{
    if ((UserEmail.Text == "x") &&
            (UserPass.Text == "x"))
    {
        FormsAuthentication.RedirectFromLoginPage
           (UserEmail.Text, Persist.Checked);
    }
    else
    {
        Msg.Text = "Invalid credentials. Please try again.";
    }
}

【问题讨论】:

    标签: asp.net styles


    【解决方案1】:

    将此添加到您的web.Config 文件中的Configuration 部分下。它将允许匿名用户访问App_Themes 文件夹。

    <location path="App_Themes">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
    </location>
    

    【讨论】:

    • 感谢您的回答,但是,这不是我的问题的答案。反正我给了你一点。如果站点在未经过身份验证时无法访问样式,但在经过身份验证时可以访问,这将是答案。 allow users="*" 为每个人提供访问权限,无论他们是否经过身份验证。就我而言,该站点根本无法访问样式文件。我将在下面发布发生的事情。
    【解决方案2】:

    我会尝试将自定义位置添加到您的 web.config 并允许 * 并查看它是否会选择样式。

    【讨论】:

    • 未经身份验证的可能是 ? 但 +1,因为我认为这是正确的方向
    【解决方案3】:

    在过去,我总是记得通过右键单击我网站的根文件夹来访问我网站的文件,并授予对以下内容的访问权限:

    服务器(又名位置):本地机器 IIS_IUSRS

    但是,由于某种原因,IUSR 不在组 IIS_IUSRS 中。我最终只是让 IUSR 用户访问我的网站,而不是该组。我了解到,您实际上可以通过转到计算机 > 管理 > 管理用户和组 > ...

    将用户 IUSR 放入组 IIS_IUSRS

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多