日期:2014-05-18  浏览次数:20366 次

身份验证的问题(高手help me)
大家好,帮忙指点一下。
我在做身份验证的时候使用cookies   来实现的。
在web.config   中   我用 <authentication   mode= "Forms ">
<forms   name= "log "   loglinUrl= "Login.aspx "   protection= "All "   />
</authentication>
<authorization>
<deny   users= "? "/>
</authorization>
但是我很郁闷,这样的验证在每个aspx页面都有效。以至于我有的页面不能显示出来(如我在做登录时,用到生成验证码的页面,因为它没有通过验证所以它显示不了)我有个问题就是我想部分页面需要验证,有的页面不需要验证。用上面的验证方法能实现么?(不用session())

------解决方案--------------------
不懂也要帮楼主顶顶
------解决方案--------------------
webconfig里
<authentication mode= "Forms ">
<forms name= "Cookie " loginUrl= "index.aspx " protection= "All " timeout= "30 ">
</forms>
</authentication>

<!-- 授权
此节设置应用程序的授权策略。可以允许或拒绝不同的用户或角色访问
应用程序资源。通配符: "* " 表示任何人, "? " 表示匿名
(未经身份验证的)用户。
-->

<authorization>
<allow users= "* " /> <!-- 允许所有用户 -->
<!-- <allow users= "[逗号分隔的用户列表] "
roles= "[逗号分隔的角色列表] "/>
<deny users= "[逗号分隔的用户列表] "
roles= "[逗号分隔的角色列表] "/>
-->

登录成功加上下面的代码
FormsAuthentication.SetAuthCookie(this.txtName.Text,true);
Response.Write( " <script> top.location.href= 'manage.aspx '; </script> ");

然后在需要验证的页面的page_load里加
if(User.Identity.AuthenticationType)
{
.......
}
else
{
跳转到你的登录页
}
------解决方案--------------------
错了,是

if(User.Identity.IsAuthenticated)
------解决方案--------------------
不需要验证的页面放在location节中重新指定
------解决方案--------------------
<configuration>
<location path= "Logon.aspx ">
<system.web>
<authorization>
<allow users= "? "/>
</authorization>
</system.web>
</location>
</configuration>

------解决方案--------------------
楼上正解!补充一下:
<configuration>
<location path= "Login.aspx ">
<system.web>
<authorization>
<allow users= "? "/>
</authorization>
</system.web>
</location>
</configuration>
------解决方案--------------------
楼上快了一步,抢了我的祥解
------解决方案--------------------
简单一点

web.config里
<authentication mode= "Forms ">
<forms name= "log " loglinUrl= "Login.aspx " protection= "All " />
</authentication>
<authorization>
<allow users= "* " />
</authorization>

把需要验证的文件都放在一个文件夹下,这下面再给一个Web.config
<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<system.web>