在我的解决方案中有一个文件夹里面放的是用户页面(需要验证才能登陆)于是我在这个页面添加了一个Web.config.里面的内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<authentication mode="Forms"> 
    <forms loginUrl="login.aspx" />
</authentication>
   <authorization>
        <allow deny="?" />     
   </authorization>
</system.web>
</configuration>
提示出错     我把<authentication mode="Forms"> 
    <forms loginUrl="login.aspx" />
    </authentication>删除掉就好了,可是这样的话页面怎么验证呢,具体怎么实现呢????

解决方案 »

  1.   

    <authentication mode="Forms"> 
        <forms loginUrl="login.aspx" />
        </authentication>
    在根目录下的webconfig里。.
      

  2.   

    那我从首页登陆成功连接到,该用户页面,它又会被定向到login.aspx 怎么办
      

  3.   

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <location path="login">  'login目录允许所有用户
        <system.web>
          <authorization>
            <allow users="*" />
          </authorization>
        </system.web>
      </location>
      <location path="admin">  'admin目录,拒绝匿名用户
        <system.web>
          <authorization>
            <deny users="?" />
          </authorization>
        </system.web>
      </location>
      
    <system.web>
        <authentication mode="Forms">
          <forms loginUrl="login/" name="dep">
            <credentials passwordFormat="MD5">
              <user name="dep" password="EFE356707C255C11ED5AEE07C28BB91A" />
            </credentials>
          </forms>
        </authentication>
    </system.web>
    </configuration>
      

  4.   

    <allow deny="?" />
    要不就allow要不就deny,不要写一起
            <deny users="xxx"/>
            <allow users="Hello"/>
      

  5.   

    Forms验证方式就是对一个项目中页面访问进行验证
    也就是一定要先login若不采这方法,则可以每个页中加一段方法判断是否登录,如判断Session有没有值
      

  6.   

    用Forms验证方式就是对一个项目中页面访问进行验证
    也就是一定要先login  
    没法实现  类似在每个页中加一段方法判断是否登录,如判断Session有没有值吗
      

  7.   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
                If Session("UserName") Is Nothing Then
                    Response.Redirect("login.aspx")
                End If
            End If
        End Sub
      

  8.   

    我认为这么判断也很方便。
    using System;
    using System.Web;
    namespace BR
    {
        public class MyPageBase : System.Web.UI.Page
        {
                  
            public MyPageBase()
            {
        
            }
            protected override void OnInit(EventArgs e)
            { 
                if((LoginUser)Session["LoginUser"] == null)
                {
                    Response.Redirect(HttpContext.Current.Request.ApplicationPath + "/Login.aspx", true);
                }
                base.OnInit(e);           
            }
        }
    }在每一页都继承这个类。
    public partial class WebForm1 : BR.MyPageBase
      

  9.   

    To fjleague(Shadow) 你总不能每个页都这样加判断吧? 这样要用多多少功夫呀
      

  10.   

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <authentication mode="Forms"> 
        <forms loginUrl="login.aspx" />
    </authentication>
       <authorization>
            <allow users="?" />
             <allow users="*" />     
       </authorization>
    </system.web>
    </configuration>