2009-12-08 82 views
6

此規範在根web.config文件中是否正確?我沒有在受保護的文件夾中使用小孩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> 

回答

4

,您應該設置一個包含下列元素的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文件中chield文件夾級聯,你的假設是正確的,使用登錄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> 
0

下配置標籤和認證元素添加的ConnectionStrings元素的System.Web標籤。

<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這裏