积极答复者
web.config中如何设置某些目录需要登录验证?

问题
-
<authentication mode="Forms">
<forms loginUrl="Systems/NewsSystem/admin/Login.aspx" protection="All" timeout="30" name=".ASPXAUTH"
path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx"
cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<!-- 以上设置是让这个程序都需要登录验证!我在用如下代码只能让某些目录不需要验证,而我下载的需要恰恰相反,我想只是某个目录如:Systems/NewsSystem/admin目录需要验证!怎么做呀?-->
<location path="Systems/NewsSystem/admin">
<system.web>
<authorization>
<!--deny users="?"/-->
<allow users="?"/>
</authorization>
</system.web>
</location>
www.haodd123.com 我是半路出家,而且是自学 学的是C#语言,希望回帖的高手们留意一下,谢谢大家的帮助
答案
-
你好,
把你的代码按照邹俊才版主的提示稍微改改就好了。你试试下面这种方式:
<authentication mode="Forms"> <forms loginUrl="Systems/NewsSystem/admin/Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <!-- 如果只是想让某一路径下的访问需要验证可以把这个注释掉 <authorization> <deny users="?"/> </authorization> --> <location path="Systems/NewsSystem/admin"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>
Microsoft Online Community Support- 已标记为答案 lkf18 2010年4月15日 18:12
-
你好,
把你的代码按照邹俊才版主的提示稍微改改就好了。你试试下面这种方式:
<authentication mode="Forms"> <forms loginUrl="Systems/NewsSystem/admin/Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <!-- 如果只是想让某一路径下的访问需要验证可以把这个注释掉 <authorization> <deny users="?"/> </authorization> --> <location path="Systems/NewsSystem/admin"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>
Microsoft Online Community Support- 已标记为答案 lkf18 2010年4月15日 18:12
全部回复
-
< authentication mode ="Forms" >
< forms loginUrl ="Systems/NewsSystem/admin/Login.aspx" protection ="All" timeout ="30" name =".ASPXAUTH"
path ="/" requireSSL ="false" slidingExpiration ="true" defaultUrl ="default.aspx"
cookieless ="UseDeviceProfile" enableCrossAppRedirects ="false" />
</ authentication >
< authorization >
< deny users ="?" />
</ authorization >
<!-- 以上设置是让这个程序都需要登录验证!我在用如下代码只能让某些目录不需要验证,而我下载的需要恰恰相反,我想只是某个目录如:Systems/NewsSystem/admin目录需要验证!怎么做呀? -->
< location path ="Systems/NewsSystem/admin" >
< system.web >
< authorization >
<!-- deny users="?"/ -->
< allow users ="?" />
</ authorization >
</ system.web >
</ location >
www.haodd123.com 我是半路出家,而且是自学 学的是C#语言,希望回帖的高手们留意一下,谢谢大家的帮助
设置目录的话,就用<location>这个节点就可以了。 -
<!--控制对 URL 资源的客户端访问(如允许匿名用户访问)。此元素可以在任何级别(计算机、站点、应用程序、子目录或页)上声明。必需与<authentication> 节配合使用。此处的意思是对匿名用户不进行身份验证。拒绝用户weipeng-->
<authorization>
<allow users="*"/>
<deny users="weipeng"/>
<allow users="aa" roles="aa" />
</authorization>
http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html
-
你好,
把你的代码按照邹俊才版主的提示稍微改改就好了。你试试下面这种方式:
<authentication mode="Forms"> <forms loginUrl="Systems/NewsSystem/admin/Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <!-- 如果只是想让某一路径下的访问需要验证可以把这个注释掉 <authorization> <deny users="?"/> </authorization> --> <location path="Systems/NewsSystem/admin"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>
Microsoft Online Community Support- 已标记为答案 lkf18 2010年4月15日 18:12
-
你好,
把你的代码按照邹俊才版主的提示稍微改改就好了。你试试下面这种方式:
<authentication mode="Forms"> <forms loginUrl="Systems/NewsSystem/admin/Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <!-- 如果只是想让某一路径下的访问需要验证可以把这个注释掉 <authorization> <deny users="?"/> </authorization> --> <location path="Systems/NewsSystem/admin"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>
Microsoft Online Community Support- 已标记为答案 lkf18 2010年4月15日 18:12