web.config:
<configuration>
  <system.web>
      <authentication mode="None">
        <forms name=".ASPXUSERDEMO" loginUrl="login.aspx" protection="All" timeout="60" />
      </authentication>
      <authorization>
        <deny users="?" />
      </authorization>
    <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" />
  </system.web>
</configuration>
--------------------------
login.aspx
:
<%@ Import Namespace="System.Web.Security " %><html>
   <script language="C#" runat=server>    void Login_Click(Object sender, EventArgs E) {      // authenticate user: this samples accepts only one user with
      // a name of [email protected] and a password of 'password'      if ((UserEmail.Value == "[email protected]") && (UserPass.Value == "密码")) {
        FormsAuthentication.RedirectFromLoginPage(UserEmail.Value, PersistCookie.Checked);
      }
      else {
        Msg.Text = "凭据无效:请再试一次";
      }
    }  </script>  <body>    <form runat=server>      <h3><font face="宋体">登录页</font></h3>      <table>
        <tr>
          <td>电子邮件:</td>
          <td><input id="UserEmail" type="text" runat=server/></td>
          <td><ASP:RequiredFieldValidator ControlToValidate="UserEmail" Display="Static" ErrorMessage="*" runat=server/></td>
        </tr>
        <tr>
          <td>密码:</td>
          <td><input id="UserPass" type=password runat=server/></td>
          <td><ASP:RequiredFieldValidator ControlToValidate="UserPass" Display="Static" ErrorMessage="*" runat=server/></td>
        </tr>
        <tr>
          <td>持久的 Cookie:</td>
          <td><ASP:CheckBox id=PersistCookie runat="server" /> </td>
          <td></td>
        </tr>
      </table>      <asp:button text="登录" OnClick="Login_Click" runat=server/>      <p>      <asp:Label id="Msg" ForeColor="red" Font-Name="Verdana" Font-Size="10" runat=server />    </form>
  </body></html>-----------------------
default.aspx:
<%@ Import Namespace="System.Web.Security " %><html>
   <script language="C#" runat=server>    void Page_Load(Object Src, EventArgs E ) {      Welcome.Text = "Hello, " + User.Identity.Name;
    }    void Signout_Click(Object sender, EventArgs E) {      FormsAuthentication.SignOut();
      Response.Redirect("login.aspx");
    }  </script>  <body>    <h3><font face="宋体">使用 Cookie 身份验证</font></h3>    <form runat=server>      <h3><asp:label id="Welcome" runat=server/></h3>      <asp:button text="注销" OnClick="Signout_Click" runat=server/>    </form>  </body></html>-------------------------------------------
浏览时报错:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------配置错误 
说明: 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。 分析器错误信息: 在应用程序级别以外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。导致该错误的原因可能是在 IIS 中没有将虚拟目录作为应用程序进行配置。源错误: 
行 1:  <configuration>
行 2:    <system.web>
行 3:        <authentication mode="None">
行 4:          <forms name=".ASPXUSERDEMO" loginUrl="login.aspx" protection="All" timeout="60" />
行 5:        </authentication>
 源文件: D:\www\web login\forms\web.config    行: 3 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573 
搞不定,

解决方案 »

  1.   

    IIS 中没有将虚拟目录作为应用程序进行配置?这句话说的很清楚,常遇到这样的问题,你在IIS新建虚拟目录,虚拟目录---应用程序设置---创建。看看这样可以?
      

  2.   

    <authentication mode="Forms">
      

  3.   

    我也遇到过,同意 gavintolee(gavin)
      

  4.   

    <authentication mode="Forms">
      

  5.   

    我也遇到过,同意 gavintolee(gavin)
      

  6.   

    IIS 中没有将虚拟目录作为应用程序进行配置?这句话说的很清楚,常遇到这样的问题,你在IIS新建虚拟目录,虚拟目录---应用程序设置---创建。看看这样可以?
    <authentication mode="Forms">--------------------------------------------------------
    还是不行呀
      

  7.   

    难道:虚拟目录的:名称必须为:forms?
      

  8.   

    web.config必须放在根目录下.所有的.dll文件必须放在bin文件夹下.