从静态类访问页,当前实例 [英] Access current instance of Page from a static class

查看:80
本文介绍了从静态类访问页,当前实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本的问题 - 是否有可能从一个静态类访问当前在ASP.NET

Basic question - is it possible to access the current Page from a static class in ASP.NET?

我想没有,因为谷歌变成了没有结果。

I am thinking no, as google turns up no results.

推荐答案

从技术上讲,你可以只获得当前的的IHttpHandler 的请求。由于网页实现这一点,那么你可以检查,看它是否是之一。

Technically you could just get the current IHttpHandler for the request. Since Page implements that, then you could check to see if it is one.

var page = HttpContext.Current.CurrentHandler as Page;

if(page != null){
    // Do something with page
}

这篇关于从静态类访问页,当前实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆