[英]What are ways to update ASP.NET page from HttpModule?
我需要永久或不定期地從HttpModule更新ASP.NET頁面。
這是要更新的頁面的IUpdatablePage接口的代碼:
interface IUpdatablePage
{
void Update( string value );
}
我想這是HttpModule的代碼可以是:
void IHttpModule.Init( HttpApplication application )
{
application.PreRequestHandlerExecute += new EventHandler( application_PreRequestHandlerExecute );
}
void application_PreRequestHandlerExecute( object sender, EventArgs e )
{
this._Page = ( Page )HttpContext.Current.Handler;
}
void HttpModuleProcessing()
{
//... doing smth
IUpdatablePage page = this._Page as IUpdatablePage;
page.Update( currentVaue );
//... continue doing smth
}
在這里,我們:
現在,頁面將在Update函數中獲取值。
public partial class MyPage: System.Web.Page, IUpdatablePage
{
void IUpdatablePage.Update( string value )
{
// Here we need to update the page with new value
Label1.Text = value;
}
}
問題是,有什么方法可以將此值傳輸到Webform控件,以便它們可以立即在瀏覽器中顯示它?
我想以任何方式刷新頁面:使用UpdatePanel,Timer,iframe塊,javascript等。
注意,刷新時正在HttpModule中處理來自頁面的請求。 請幫助代碼示例(我是網絡初學者)。
在Page和HttpModule之間傳輸數據的方法是使用應用程序命名的靜態對象,該對象由會話ID標識。 該頁面通過計時器觸發的UpdatePanel更新。
HttpModule的代碼(簡體):
public class UploadProcessModule : IHttpModule
{
public void Init( HttpApplication context )
{
context.BeginRequest += context_BeginRequest;
}
void context_BeginRequest( object sender, EventArgs e )
{
HttpContext context = ( ( HttpApplication )sender ).Context;
if ( context.Request.Cookies["ASP.NET_SessionId"] != null )
{
string sessionId = context.Request.Cookies["ASP.NET_SessionId"].Value;
context.Application["Data_" + sessionId] = new MyClass();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.