Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net &引用;请求在此上下文中不可用”;在IHTTP模块中_.net_Iis 7_Webrequest_Ihttpmodule - Fatal编程技术网

.net &引用;请求在此上下文中不可用”;在IHTTP模块中

.net &引用;请求在此上下文中不可用”;在IHTTP模块中,.net,iis-7,webrequest,ihttpmodule,.net,Iis 7,Webrequest,Ihttpmodule,当我尝试访问HttpContext.Current.Request对象时,会出现该异常 我已经在中看到了回应,并且。。。所以我的问题是: IHttpModules现在到底是为了什么 我想开发一个模块,每次进入may网站的电话都会被点击,这样我就可以记录访问的url、用户IP地址等,但现在看来我在IIS7里再也做不到了。有什么解决办法吗?(除了切换到“经典模式”) 干杯。我最初将此作为一条评论发布,因为这不是一个真正的答案,但后来我看到您正在寻找一个“变通方案”,所以这里是我对变通方案的想法 /

当我尝试访问HttpContext.Current.Request对象时,会出现该异常

我已经在中看到了回应,并且。。。所以我的问题是:

IHttpModules现在到底是为了什么

我想开发一个模块,每次进入may网站的电话都会被点击,这样我就可以记录访问的url、用户IP地址等,但现在看来我在IIS7里再也做不到了。有什么解决办法吗?(除了切换到“经典模式”)


干杯。

我最初将此作为一条评论发布,因为这不是一个真正的答案,但后来我看到您正在寻找一个“变通方案”,所以这里是我对变通方案的想法

/App\u Code/BasePage.vb

 Public Class BasePage : Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''# Do all your logging here
    End Sub
 End Class
Partial Class _Default : Inherits BasePage
    ''# This is simply your code behind for each page (notice it inherits BasePage)
    ''# You can still have your Page_Load events along with custom methods in here, 
    ''# and it will not affect the logging portion of your app.
End Class
/Default.aspx.vb

 Public Class BasePage : Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''# Do all your logging here
    End Sub
 End Class
Partial Class _Default : Inherits BasePage
    ''# This is simply your code behind for each page (notice it inherits BasePage)
    ''# You can still have your Page_Load events along with custom methods in here, 
    ''# and it will not affect the logging portion of your app.
End Class

基本上,您所做的是创建一个类,该类在每次加载页面时都执行相同的工作,而不管加载的是什么页面。然后,应用程序中的每个页面都将继承自
BasePage
类,以便激活它。

我最初将此作为注释发布,因为它不是真正的答案,但后来我发现您正在寻找一个“变通方法”,所以这里是我关于变通方法的想法

/App\u Code/BasePage.vb

 Public Class BasePage : Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''# Do all your logging here
    End Sub
 End Class
Partial Class _Default : Inherits BasePage
    ''# This is simply your code behind for each page (notice it inherits BasePage)
    ''# You can still have your Page_Load events along with custom methods in here, 
    ''# and it will not affect the logging portion of your app.
End Class
/Default.aspx.vb

 Public Class BasePage : Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''# Do all your logging here
    End Sub
 End Class
Partial Class _Default : Inherits BasePage
    ''# This is simply your code behind for each page (notice it inherits BasePage)
    ''# You can still have your Page_Load events along with custom methods in here, 
    ''# and it will not affect the logging portion of your app.
End Class

基本上,您所做的是创建一个类,该类在每次加载页面时都执行相同的工作,而不管加载的是什么页面。然后应用程序中的每个页面都将继承自
BasePage
类,以便激活它。

您什么时候这样做?是否在模块事件中? 它在集成池中也应该是完全可行的。 一句话,ASP.NET在集成模式下运行时如何钩住IIS的方式发生了变化,使其“更一流”。这确实意味着某些事件在之前触发,例如应用程序启动现在将在实际请求的上下文之外触发。其他示例希望在BeginRequest中有一个Windows身份验证,因为现在BeginRequest甚至在IIS身份验证之前发生,而过去不是这样

如果您的应用程序依赖于旧的不良行为,那么您仍然可以将应用程序池更改为在经典模式下运行,它将正常工作

您应该能够在任何特定于请求的通知中获取请求,例如BeginRequest、EndRequest、PostAuthorizerRequest等。 此外,我建议不要使用HttpContext.Current,因为这会导致在哈希表中进行额外的查找,通常可以通过其他方式直接获取上下文,特别是在模块的上下文中,因此,例如,如果处理BeginRequest,您应该能够:

    HttpApplication application = (HttpApplication)sender;  
    HttpContext context = application.Context;  
您将保存查找


根据您的描述,听起来您应该实现一个处理BeginRequest和EndRequest的模块,您应该很好。

您什么时候这样做?是否在模块事件中? 它在集成池中也应该是完全可行的。 一句话,ASP.NET在集成模式下运行时如何钩住IIS的方式发生了变化,使其“更一流”。这确实意味着某些事件在之前触发,例如应用程序启动现在将在实际请求的上下文之外触发。其他示例希望在BeginRequest中有一个Windows身份验证,因为现在BeginRequest甚至在IIS身份验证之前发生,而过去不是这样

如果您的应用程序依赖于旧的不良行为,那么您仍然可以将应用程序池更改为在经典模式下运行,它将正常工作

您应该能够在任何特定于请求的通知中获取请求,例如BeginRequest、EndRequest、PostAuthorizerRequest等。 此外,我建议不要使用HttpContext.Current,因为这会导致在哈希表中进行额外的查找,通常可以通过其他方式直接获取上下文,特别是在模块的上下文中,因此,例如,如果处理BeginRequest,您应该能够:

    HttpApplication application = (HttpApplication)sender;  
    HttpContext context = application.Context;  
您将保存查找


根据您的描述,听起来您应该实现一个处理BeginRequest和EndRequest的模块,您应该很好。

这不是对您问题的回答,而是一个替代方案。为什么不创建一个继承自
System.Web.Ui.Page
类的
BasePage
类呢。现在,您的所有页面都可以从
BasePage
继承。然后,您可以在进行日志记录的
BasePage
中添加自己的
Page\u Load
事件。这不是对您的问题的回答,而是一种替代方法。为什么不创建一个继承自
System.Web.Ui.Page
类的
BasePage
类呢。现在,您的所有页面都可以从
BasePage
继承。然后,您可以在进行日志记录的
BasePage
中添加您自己的
Page\u Load
事件。如果您使用C,当然可以将其转换为C,我非常感谢,但我没有使用ASP.NET UI类:P谢谢!我自己的UI类:D希望在下个月我会重新开发它们,生成html5代码,而不是html4。如果你使用C,当然可以将其转换为C,我非常感谢,但我没有使用ASP.NET UI类:P谢谢!我自己的UI类:D希望在下个月我会重新开发它们,生成html5代码,而不是html4。