1

我如何将目录设置为只有经过身份验证的用户才能访问文件的目录?

换句话说,我需要确保只有登录的人才能使用 web.config 访问图像和其他人的数据。

有哪些设置?

这是我到目前为止所得到的,但它不会阻止未登录的用户。

    <?xml version="1.0"?>
<configuration>
  <system.web>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
</configuration>

我的 web.config 文件删除了大部分信息。如果您可以将该配置信息放置在它所在的位置,以便我网站上的任何人都无法访问名为 users 的文件夹,除非他们已登录。

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings configSource="cnn.config" />
  <appSettings configSource="app.config" />
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime requestValidationMode="4.5" targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <machineKey compatibilityMode="Framework45" />
    <authentication configSource="authentication.config" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
      </controls>
    </pages>
    <membership configSource="membership.config" />
    <roleManager configSource="roles.config" />
    <profile configSource="profile.config" />
      <!--<sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>-->
  </system.web>
</configuration>
4

1 回答 1

1

看看这篇文章:如何:控制 ASP.NET 应用程序中的授权权限

简而言之,您可以像这样设置文件夹权限:

<configuration>
    <location path="images">
        <system.web>
            <authorization>
                <deny users ="?" />
            </authorization>
        </system.web>
    </location>
</configuration>
于 2013-11-05T19:29:50.343 回答