ASP.NET登录系统

时间:2012-04-29 20:33:34

标签: asp.net

我已经为我的网站创建了一个登录系统。此登录系统应该仅保护一个页面(意味着有一个页面需要用户登录才能看到它)。 我的问题是: 自从我创建了这个登录系统以来,我所有其他8个页面现在都需要验证。这不是我的意图,我一直在疯狂寻找解决方案,但没有运气。 我的web.config文件如下所示:

<configuration>
<system.web>
  <compilation debug="true" targetFramework="4.0">
    <assemblies>
      <add assembly="MySql.Data, Version=5.0.9.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
    </assemblies>
  </compilation>

  <authentication mode="Forms">
    <forms loginUrl="Login.aspx" name=".ASPXFORMSAUTH" timeout="30" />  <!--name =".ASPXFORMSAUTH"-->
  </authentication>

  <authorization>
    <deny users="?" />
  </authorization>
</system.web>

唯一需要登录的页面称为Default.aspx 我的其他页面应该对所有用户公开。我怎样才能做到这一点? 感谢

2 个答案:

答案 0 :(得分:3)

您可以使用web.config文件中的location元素来完成。

<location path="Default.aspx"> 
  <system.web> 
      <authorization> 
            <deny users="?" />
      </authorization> 
   </system.web> 
</location> 

答案 1 :(得分:2)

在web.config中使用“location”并指定要保护的目录。这是一个很好的例子:

http://www.codefixer.com/asp-net/tutorials/protecting-folders-with-forms-authentication.asp