Postback error after using HttpModule

N

nail

Folks,
I develop a HttpModule and it works correct, but one problem is occurs.
After I register the httpmodule in the web.config, my pages (not testing
http://localhost/site but http://my_machine_name/site) show problems when
refresh the page.
I guess some kind of javascript problems with the postback methods.

Someone has any idea how can i fix it?

Thanks

nail
 
S

Scott Allen

Hi nail:

We would have to know a little bit about what the HttpModule does. Can
you post some code?
 
N

nail

Ok Scott.
Here's the httpmodule class:
Thanks again.

public class STHttpModule : IHttpModule

{

private Page pg;

public void Init(HttpApplication httpApp)

{//Check if the page is the asp.net configuration. if is, not execute the
http module handler.

if (httpApp.Context.Request.Url.ToString().ToLower().IndexOf("webadmin")
== -1)

httpApp.PreRequestHandlerExecute += new
EventHandler(httpApp_PreRequestHandlerExecute);

}

public void Dispose()

{

// not necessary

}


void pg_PreInit(object sender, EventArgs e)

{

if (pg.Request["CurrentTheme1"] != null)

pg.Theme = pg.Request["CurrentTheme1"].ToString();

}

void httpApp_PreRequestHandlerExecute(object sender, EventArgs e)

{

pg = (Page)HttpContext.Current.Handler;

pg.PreInit += new EventHandler(pg_PreInit);

}

}
 
S

Scott Allen

Hi nail:

One thing that seems a little odd is the way you check the Url
property during Init. The Init method will only be invoked once and
then the module will be reused for several requests. If the first
request then, is not for "webadmin", then you'll never be hooking the
PreRequestHandlerExecute event.

Instead, I'd always hook that event and then check the URL during the
Begin_Request event.

--
Scott
http://www.OdeToCode.com/

Ok Scott.
Here's the httpmodule class:
Thanks again.

public class STHttpModule : IHttpModule

{

private Page pg;

public void Init(HttpApplication httpApp)

{//Check if the page is the asp.net configuration. if is, not execute the
http module handler.

if (httpApp.Context.Request.Url.ToString().ToLower().IndexOf("webadmin")
== -1)

httpApp.PreRequestHandlerExecute += new
EventHandler(httpApp_PreRequestHandlerExecute);

}

public void Dispose()

{

// not necessary

}


void pg_PreInit(object sender, EventArgs e)

{

if (pg.Request["CurrentTheme1"] != null)

pg.Theme = pg.Request["CurrentTheme1"].ToString();

}

void httpApp_PreRequestHandlerExecute(object sender, EventArgs e)

{

pg = (Page)HttpContext.Current.Handler;

pg.PreInit += new EventHandler(pg_PreInit);

}

}
 
N

nail

Ok Scott, now I check if the page is webadmin in the Begin_Request event.
But the problem continues.
And in pages with webparts, I get javascript erros like "WebPartZone is
undefined"
And in the other pages, the same postback error like
'WebForm_PostBackOptions' is undefined

I don't know how can I fix it!!

Thanks.


Scott Allen said:
Hi nail:

One thing that seems a little odd is the way you check the Url
property during Init. The Init method will only be invoked once and
then the module will be reused for several requests. If the first
request then, is not for "webadmin", then you'll never be hooking the
PreRequestHandlerExecute event.

Instead, I'd always hook that event and then check the URL during the
Begin_Request event.

--
Scott
http://www.OdeToCode.com/

Ok Scott.
Here's the httpmodule class:
Thanks again.

public class STHttpModule : IHttpModule

{

private Page pg;

public void Init(HttpApplication httpApp)

{//Check if the page is the asp.net configuration. if is, not execute the
http module handler.

if (httpApp.Context.Request.Url.ToString().ToLower().IndexOf("webadmin")
== -1)

httpApp.PreRequestHandlerExecute += new
EventHandler(httpApp_PreRequestHandlerExecute);

}

public void Dispose()

{

// not necessary

}


void pg_PreInit(object sender, EventArgs e)

{

if (pg.Request["CurrentTheme1"] != null)

pg.Theme = pg.Request["CurrentTheme1"].ToString();

}

void httpApp_PreRequestHandlerExecute(object sender, EventArgs e)

{

pg = (Page)HttpContext.Current.Handler;

pg.PreInit += new EventHandler(pg_PreInit);

}

}



Scott Allen said:
Hi nail:

We would have to know a little bit about what the HttpModule does. Can
you post some code?

--
Scott
http://www.OdeToCode.com/


Folks,
I develop a HttpModule and it works correct, but one problem is occurs.
After I register the httpmodule in the web.config, my pages (not testing
http://localhost/site but http://my_machine_name/site) show problems
when
refresh the page.
I guess some kind of javascript problems with the postback methods.

Someone has any idea how can i fix it?

Thanks

nail
 
S

Scott Allen

I know it only happens when you register the module, but I can't see
anything in the code that would cause the javascript to screw up...

Something I might do is a View Source on the page with and without the
module registered, and diff them to see what is changing. That might
give a clue as to where the problem is. Know what I mean?
 
S

Scott Allen

Say, any chance you are trying to dynamically load a theme in ASP.NET
2.0? You might want to check out a new article, it covers that topic:
http://msdn.microsoft.com/asp.net/whidbey/default.aspx?pull=/library/en-us/dnvs05/html/themes.asp

--
Scott
http://www.OdeToCode.com/



Ok Scott, now I check if the page is webadmin in the Begin_Request event.
But the problem continues.
And in pages with webparts, I get javascript erros like "WebPartZone is
undefined"
And in the other pages, the same postback error like
'WebForm_PostBackOptions' is undefined

I don't know how can I fix it!!

Thanks.


Scott Allen said:
Hi nail:

One thing that seems a little odd is the way you check the Url
property during Init. The Init method will only be invoked once and
then the module will be reused for several requests. If the first
request then, is not for "webadmin", then you'll never be hooking the
PreRequestHandlerExecute event.

Instead, I'd always hook that event and then check the URL during the
Begin_Request event.

--
Scott
http://www.OdeToCode.com/

Ok Scott.
Here's the httpmodule class:
Thanks again.

public class STHttpModule : IHttpModule

{

private Page pg;

public void Init(HttpApplication httpApp)

{//Check if the page is the asp.net configuration. if is, not execute the
http module handler.

if (httpApp.Context.Request.Url.ToString().ToLower().IndexOf("webadmin")
== -1)

httpApp.PreRequestHandlerExecute += new
EventHandler(httpApp_PreRequestHandlerExecute);

}

public void Dispose()

{

// not necessary

}


void pg_PreInit(object sender, EventArgs e)

{

if (pg.Request["CurrentTheme1"] != null)

pg.Theme = pg.Request["CurrentTheme1"].ToString();

}

void httpApp_PreRequestHandlerExecute(object sender, EventArgs e)

{

pg = (Page)HttpContext.Current.Handler;

pg.PreInit += new EventHandler(pg_PreInit);

}

}



Hi nail:

We would have to know a little bit about what the HttpModule does. Can
you post some code?

--
Scott
http://www.OdeToCode.com/


Folks,
I develop a HttpModule and it works correct, but one problem is occurs.
After I register the httpmodule in the web.config, my pages (not testing
http://localhost/site but http://my_machine_name/site) show problems
when
refresh the page.
I guess some kind of javascript problems with the postback methods.

Someone has any idea how can i fix it?

Thanks

nail
 
N

nail

Hi Scott.
Yeah man, I read the article and I know that.
To change the theme in runtime I need to handle the PreInit event.
But remember, I developing a custom control. And I can't want, after put my
control in the page, write an any code in the PreInit event of the page.
After all, I can't put any code in all pages os my project.

If I am not use httpmodule, I cannot get the PreInit event of the page. The
httpmodule is the only way I know.
Understand me now?

Thanks again for your greater help.
If you know anything, send me email in fer.lopes@[nospam].com.br

Scott Allen said:
Say, any chance you are trying to dynamically load a theme in ASP.NET
2.0? You might want to check out a new article, it covers that topic:
http://msdn.microsoft.com/asp.net/whidbey/default.aspx?pull=/library/en-us/dnvs05/html/themes.asp

--
Scott
http://www.OdeToCode.com/



Ok Scott, now I check if the page is webadmin in the Begin_Request event.
But the problem continues.
And in pages with webparts, I get javascript erros like "WebPartZone is
undefined"
And in the other pages, the same postback error like
'WebForm_PostBackOptions' is undefined

I don't know how can I fix it!!

Thanks.


Scott Allen said:
Hi nail:

One thing that seems a little odd is the way you check the Url
property during Init. The Init method will only be invoked once and
then the module will be reused for several requests. If the first
request then, is not for "webadmin", then you'll never be hooking the
PreRequestHandlerExecute event.

Instead, I'd always hook that event and then check the URL during the
Begin_Request event.

--
Scott
http://www.OdeToCode.com/


Ok Scott.
Here's the httpmodule class:
Thanks again.

public class STHttpModule : IHttpModule

{

private Page pg;

public void Init(HttpApplication httpApp)

{//Check if the page is the asp.net configuration. if is, not execute
the
http module handler.

if (httpApp.Context.Request.Url.ToString().ToLower().IndexOf("webadmin")
== -1)

httpApp.PreRequestHandlerExecute += new
EventHandler(httpApp_PreRequestHandlerExecute);

}

public void Dispose()

{

// not necessary

}


void pg_PreInit(object sender, EventArgs e)

{

if (pg.Request["CurrentTheme1"] != null)

pg.Theme = pg.Request["CurrentTheme1"].ToString();

}

void httpApp_PreRequestHandlerExecute(object sender, EventArgs e)

{

pg = (Page)HttpContext.Current.Handler;

pg.PreInit += new EventHandler(pg_PreInit);

}

}



Hi nail:

We would have to know a little bit about what the HttpModule does. Can
you post some code?

--
Scott
http://www.OdeToCode.com/


Folks,
I develop a HttpModule and it works correct, but one problem is
occurs.
After I register the httpmodule in the web.config, my pages (not
testing
http://localhost/site but http://my_machine_name/site) show problems
when
refresh the page.
I guess some kind of javascript problems with the postback methods.

Someone has any idea how can i fix it?

Thanks

nail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top