ASP.NET如何在Aplication Request模块中访问User.Identity.IsAuthenticated? [英] ASP.NET how to access User.Identity.IsAuthenticated in Aplication Request module?
问题描述
我在ASP.Net中使用表单身份验证方法,问题是它仅保护" .aspx"文件.我试图保护"kcfinder"文件夹中的" .php"文件免受未经身份验证的用户的侵害.
I am using Form Authentication Method in ASP.Net and the problem is it only protect ".aspx" files. I am trying to protect ".php" files in "kcfinder" folder from unauthenticated users.
我在"App_Code"文件夹中实现了此类.
I implemeted this class in "App_Code" folder.
public class KCChecker
{
public static void Process(HttpApplication Application)
{
HttpRequest Request = Application.Context.Request;
HttpResponse Response = Application.Context.Response;
string url = Request.Path.ToLower();
if (url.IndexOf("/kcfinder/") == 0 && !HttpContext.Current.User.Identity.IsAuthenticated)
{
Response.Redirect("/");
}
}
}
问题在于它总是说对象引用未设置为对象的实例".在HttpContext.Current.User.Identity.IsAuthenticated
上.我试图将其更改为Application.Context.User.Identity.IsAuthenticated
,但仍然显示相同的错误.
The problem is it always say "Object reference not set to an instance of an object." on HttpContext.Current.User.Identity.IsAuthenticated
. I tried to change it to Application.Context.User.Identity.IsAuthenticated
but it still shows the same error.
我可以通过此自定义模块的Process函数访问User Object吗?
Is there any way I can access User Object in this custom module's Process function?
推荐答案
将以下内容添加到您的web.config文件中:
Add the following to your web.config file:
<modules runAllManagedModulesForAllRequests="true" />
这篇关于ASP.NET如何在Aplication Request模块中访问User.Identity.IsAuthenticated?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!