Application_BeginRequest和Page对象 [英] Application_BeginRequest and the Page object

查看:73
本文介绍了Application_BeginRequest和Page对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否可以以编程方式访问

Application_BeginRequest中的Page对象,或者在生命周期中是否过早...... ?


例如能够动态更改页面的MasterPage,如:


protected void Application_BeginRequest(Object sender,EventArgs e)

{

if(Session [" LoggedOn"] ==" True")

{

< page> .MasterPageFile ="〜/ loggedOn .master" ;;

}

其他

{

< page> .MasterPageFile ="〜/ notLoggedOn.master" ;;

}

}


NB我意识到有可能以其他方式实现上述功能......这只是一个假设的例子......


感激的任何帮助收到。


马克

Hi,

Is it possible to have programmatic access to the Page object in
Application_BeginRequest, or is it too early in the lifecycle...?

E.g. to be able to change a page''s MasterPage dynamically, something like:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Session["LoggedOn"] == "True")
{
<page>.MasterPageFile = "~/loggedOn.master";
}
else
{
<page>.MasterPageFile = "~/notLoggedOn.master";
}
}

N.B. I realise it''s possible to achieve the above functionality in other
ways - it''s just a hypothetical example...

Any assistance gratefully received.

Mark

推荐答案

re:

是否可以在Application_BeginRequest中以编程方式访问Page对象,或者在生命周期中过早提供

Is it possible to have programmatic access to the Page object in Application_BeginRequest, or is
it too early in the lifecycle...?



问题是针对* all *的请求引发了Application_BeginRequest事件。


你确定要的是那个代码每次您的应用程序收到请求时执行?


查看应用程序生命周期概述:
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

和ASP.NET页面生命周期概述,位于:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx


我敢肯定你''在这两页中的一页中找到更合适的应用程序或页面,

事件代码。


Juan T. Llibre, asp.net MVP

aspnetfaq.com: http://www.aspnetfaq的.com /

asp.net faq: http:// asp。 net.do/faq/

foros de asp.net,en espa?ol: http://asp.net.do/foros/

================== =================

" Mark Rae" < ma ** @ markNOSPAMrae.com在消息新闻中写道:%2 **************** @ TK2MSFTNGP03.phx.gbl ...

The problem is that the Application_BeginRequest event is raised for *all* requests.

Are you sure you want that code to execute every time your application receives a request?

Check out the Application Lifecycle Overview at :
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

and the ASP.NET Page Life Cycle Overview, at :
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

I''m sure you''ll find a more appropiate application, or page,
event for that code in one of those two pages.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...





是否可以在Application_BeginRequest中以编程方式访问Page对象,或者在生命周期中过早地使用
......?


例如能够动态更改页面的MasterPage,如:


protected void Application_BeginRequest(Object sender,EventArgs e)

{

if(Session [" LoggedOn"] ==" True")

{

< page> .MasterPageFile ="〜/ loggedOn .master" ;;

}

其他

{

< page> .MasterPageFile ="〜/ notLoggedOn.master" ;;

}

}


NB我意识到以其他方式实现上述功能是可能的 - 它只是一个假设的例子......


感激的任何帮助收到。


马克
Hi,

Is it possible to have programmatic access to the Page object in Application_BeginRequest, or is
it too early in the lifecycle...?

E.g. to be able to change a page''s MasterPage dynamically, something like:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Session["LoggedOn"] == "True")
{
<page>.MasterPageFile = "~/loggedOn.master";
}
else
{
<page>.MasterPageFile = "~/notLoggedOn.master";
}
}

N.B. I realise it''s possible to achieve the above functionality in other ways - it''s just a
hypothetical example...

Any assistance gratefully received.

Mark


>
>



Mark,

Scott Allen对MasterPages的整洁技巧有着非常深入的了解:< > http://www.odetocode.com/Articles /450.aspx


彼得


-

联合创始人,Eggheadcafe.com开发者门户网站:
http://www.eggheadcafe.com

UnBlog:
http://petesbloggerama.blogspot.com



" Mark Rae"写道:
Mark,
Scott Allen has a very in-depth piece all about neat tricks with MasterPages:

http://www.odetocode.com/Articles/450.aspx

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mark Rae" wrote:




是否可以以编程方式访问
$ b中的Page对象$ b Application_BeginRequest,还是在生命周期中太早......?


Eg能够动态更改页面的MasterPage,如:


protected void Application_BeginRequest(Object sender,EventArgs e)

{

if(Session [" LoggedOn"] ==" True")

{

< page> .MasterPageFile ="〜/ loggedOn .master" ;;

}

其他

{

< page> .MasterPageFile ="〜/ notLoggedOn.master" ;;

}

}


NB我意识到有可能以其他方式实现上述功能......这只是一个假设的例子......


感激的任何帮助收到。


Mark
Hi,

Is it possible to have programmatic access to the Page object in
Application_BeginRequest, or is it too early in the lifecycle...?

E.g. to be able to change a page''s MasterPage dynamically, something like:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Session["LoggedOn"] == "True")
{
<page>.MasterPageFile = "~/loggedOn.master";
}
else
{
<page>.MasterPageFile = "~/notLoggedOn.master";
}
}

N.B. I realise it''s possible to achieve the above functionality in other
ways - it''s just a hypothetical example...

Any assistance gratefully received.

Mark


" Juan T. Llibre" < no *********** @ nowhere.comwrote in message

news:%2 *************** @ TK2MSFTNGP05。 phx.gbl ...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...

问题是针对* all *

请求引发了Application_BeginRequest事件。
The problem is that the Application_BeginRequest event is raised for *all*
requests.



这是对的。

That''s right.


你确定你希望每次你的代码都执行申请

收到请求?
Are you sure you want that code to execute every time your application
receives a request?



谁知道 - 只是有兴趣知道,因此假设位... :-)


有可能吗?

Who knows - was just interested to know, hence the "hypothetical" bit... :-)

Is it possible?


这篇关于Application_BeginRequest和Page对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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