本文介绍了编程检查页面需要基于web.config设置验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种方法来检查,如果根据web.config中设置的页面requies认证。基本上,如果有这样的
I would like to know if there is a way to check if a page requies authentication based on the web.config settings. Basically if there is a node like this
<location path="account">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
然后我想检查任何页面上,如果它需要认证与否,如果它返回true是帐户目录下。这可能吗?
then I would like to check on any page if it requires authentication or not and to return true if it is under the account directory. Is this possible?
推荐答案
解决方案是创建一个匿名的身份(本金),并把它传递到 CheckUrlAccessForPrincipal
方法。它会确定页是公共的,或者需要验证
The solution is to create an anonymous identity (principal), and pass it into the CheckUrlAccessForPrincipal
method. It will determine if the page is public, or requires authentication.
请参阅下面的代码:
var principal = new GenericPrincipal(new GenericIdentity(String.Empty, String.Empty), new string[]{});
bool requiredAuthentication = UrlAuthorizationModule.CheckUrlAccessForPrincipal(Page.AppRelativeVirtualPath, principal, Request.HttpMethod);
这篇关于编程检查页面需要基于web.config设置验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!