【问题标题】:Forms Authentication web.config set up表单身份验证 web.config 设置
【发布时间】:2021-11-17 15:44:27
【问题描述】:

此规范在根 web.config 文件中是否正确?我没有在受保护的文件夹中使用子 web.config。

<system.web>
  <authentication mode="Forms">
    <forms name=".ASPXAUTH" loginUrl="">
    </forms>
  </authentication>
</system.web>

另外一个 system.web 规范也在根 web.config 中:

<location path="to protected folder">
  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    您应该使用以下元素设置 web.config。

    <configuration>
        <system.web>
            <authentication mode="Forms">
              <forms name="SiteName" path="/" loginUrl="~/Login.aspx" protection="All" timeout="30" />
            </authentication>
        </system.web>
    </configuration>
    

    您可以通过放置拒绝匿名访问的 web.config 来保护文件夹。

    <configuration>
      <system.web>
        <!-- Place in a sub folder that you want to protect using Forms Authentication -->
        <authorization>
          <deny users="?" />
        </authorization>
      </system.web>
    </configuration>
    

    【讨论】:

      【解决方案2】:

      web.config在子文件夹中级联,你的假设是正确的,使用登录url

      <authentication mode="Forms">
          <forms defaultUrl="~/Step1.aspx" loginUrl="~/Signup.aspx" slidingExpiration="true" timeout="1000">
            <credentials passwordFormat="Clear">
              <user name="admin" password="123.admin"/>
            </credentials>
          </forms>
      </authentication>
      <authorization>
          <allow users="admin" />
          <deny users="?"/>
      </authorization>
      

      【讨论】:

        【解决方案3】:

        在configuration标签下添加connectionStrings元素,在system.web标签下添加authentication元素。

        <connectionStrings>
        <add name="cs"connectionString="Data source=server_name; Initial Catalog=database_name;  User Id=user_id; Password=user_password" providerName="System.Data.SqlClient" />
        </connectionStrings> 
        
        <authentication mode="Forms">
             <forms loginUrl="~/Home/LogOn"defaultUrl="~/Home/Home"timeout="2880" />
        </authentication>
        

        这是一个有效的Example 这里

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-16
          • 1970-01-01
          • 2010-09-24
          • 2012-02-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多