Looking to see if anyone knows if it is possible to intercept the source of a page request prior to ASP.NET processing it so that I can make changes to the code at runtime?
I need to be able to change resource locations on the fly in my existing httpmodule. The aspx pages are proprietary and cannot be directly modified for supportability.
Got any tips on how I might be able to do that?
Currently, my httpmodule makes many changes to the response HTML, however I now need to do this to the code.
Actually no it does not. You would not change the content of the filter till it has actually been created. Think about it, if you have ot built the HTML from the httpHandler you cannot change it. If you change the content as the ASPX httpHandler is building
it, you can cause some serious issues. So you would really change it after ASPX has rendered it.
Not possible, given that ICEFIR3 wants to intercept the resource calls. Once the ASPX has rendered it will be impossible to find those places or to resolve them.
You are correct that for my needs, I must build a custom Resource Provider. However, I am actually finding it difficult to find the appropriate documentation on how to actually retrieve the resources.
The code I'm starting with (I've inserted comments where I'm having issues):
using System;
using System.Web.Compilation;
using System.Resources;
using System.Globalization;
namespace LingoShare
{
public class LingoShareFactory : ResourceProviderFactory
{
public LingoShareFactory()
{
}
public override IResourceProvider CreateGlobalResourceProvider(string className)
{
return new LSAppProvider(className);
}
public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
{
return new LSPageProvider(virtualPath);
}
}
public class LSAppProvider : IResourceProvider
{
public LSAppProvider(string className)
{
}
public object GetObject(string resourceKey, CultureInfo culture)
{
object resourceObject = null;
if (culture == null)
{
culture = CultureInfo.CurrentUICulture;
}
//WHAT DO I DO HERE?
return resourceObject;
}
public IResourceReader ResourceReader
{
get
{
throw new InvalidOperationException();
}
}
}
public class LSPageProvider : IResourceProvider
{
public LSPageProvider(string virtualPath)
{
}
public object GetObject(string resourceKey, CultureInfo culture)
{
object resourceObject;
if (culture == null)
{
culture = CultureInfo.CurrentUICulture;
}
//WHAT DO I DO HERE?
return resourceObject;
}
public IResourceReader ResourceReader
{
get
{
//WHAT DO I DO HERE?
return new ResourceReader();
}
}
}
}
ICEFIR3
0 Points
8 Posts
Change ASP.NET source from HttpModule
May 20, 2008 04:57 PM|LINK
Hi,
Looking to see if anyone knows if it is possible to intercept the source of a page request prior to ASP.NET processing it so that I can make changes to the code at runtime?
Any ideas or thoughts would be great!
Thanks!
httpmodule source asp.net
gunteman
All-Star
22406 Points
3305 Posts
Re: Change ASP.NET source from HttpModule
May 20, 2008 06:57 PM|LINK
Technically, I guess it would be tricky but possible, but why would you want to do that?
ICEFIR3
0 Points
8 Posts
Re: Change ASP.NET source from HttpModule
May 20, 2008 07:04 PM|LINK
I need to be able to change resource locations on the fly in my existing httpmodule. The aspx pages are proprietary and cannot be directly modified for supportability.
Got any tips on how I might be able to do that?
Currently, my httpmodule makes many changes to the response HTML, however I now need to do this to the code.
IE: I need to be able to convert:
<%$Resources:oldres,some_text%>
To:
<%$Resources:newres,some_text%> AND/OR <%$Resources:anothernewres,some_text%>
Thanks!
gunteman
All-Star
22406 Points
3305 Posts
Re: Change ASP.NET source from HttpModule
May 20, 2008 11:17 PM|LINK
In that case maybe you're better off by creating a custom resource provider.
http://fredrik.nsquared2.com/viewpost.aspx?PostID=157&showfeedback=true
ICEFIR3
0 Points
8 Posts
Re: Change ASP.NET source from HttpModule
May 21, 2008 11:44 AM|LINK
Thanks! I am going to try this out. If it works I'll mark your response as answer! ;)
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Change ASP.NET source from HttpModule
May 25, 2008 01:45 AM|LINK
You have to create your own Stream Class and set that equal to the Response filter. You can read how to do this in my eBook on httpModules, http://professionalaspnet.com/archive/2008/04/30/Custom-httpModules-eBook-from-WROX.aspx. I can also reccomend the source code to the Blowry Compression Module too.
gunteman
All-Star
22406 Points
3305 Posts
Re: Change ASP.NET source from HttpModule
May 25, 2008 11:26 AM|LINK
A response filter acts too late for ICEFIR3's purposes.
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Change ASP.NET source from HttpModule
May 27, 2008 12:33 AM|LINK
Actually no it does not. You would not change the content of the filter till it has actually been created. Think about it, if you have ot built the HTML from the httpHandler you cannot change it. If you change the content as the ASPX httpHandler is building it, you can cause some serious issues. So you would really change it after ASPX has rendered it.
gunteman
All-Star
22406 Points
3305 Posts
Re: Change ASP.NET source from HttpModule
May 27, 2008 05:17 AM|LINK
Not possible, given that ICEFIR3 wants to intercept the resource calls. Once the ASPX has rendered it will be impossible to find those places or to resolve them.
ICEFIR3
0 Points
8 Posts
Re: Change ASP.NET source from HttpModule
Jun 10, 2008 07:35 PM|LINK
Hey,
You are correct that for my needs, I must build a custom Resource Provider. However, I am actually finding it difficult to find the appropriate documentation on how to actually retrieve the resources.
The code I'm starting with (I've inserted comments where I'm having issues):
using System; using System.Web.Compilation; using System.Resources; using System.Globalization; namespace LingoShare { public class LingoShareFactory : ResourceProviderFactory { public LingoShareFactory() { } public override IResourceProvider CreateGlobalResourceProvider(string className) { return new LSAppProvider(className); } public override IResourceProvider CreateLocalResourceProvider(string virtualPath) { return new LSPageProvider(virtualPath); } } public class LSAppProvider : IResourceProvider { public LSAppProvider(string className) { } public object GetObject(string resourceKey, CultureInfo culture) { object resourceObject = null; if (culture == null) { culture = CultureInfo.CurrentUICulture; } //WHAT DO I DO HERE? return resourceObject; } public IResourceReader ResourceReader { get { throw new InvalidOperationException(); } } } public class LSPageProvider : IResourceProvider { public LSPageProvider(string virtualPath) { } public object GetObject(string resourceKey, CultureInfo culture) { object resourceObject; if (culture == null) { culture = CultureInfo.CurrentUICulture; } //WHAT DO I DO HERE? return resourceObject; } public IResourceReader ResourceReader { get { //WHAT DO I DO HERE? return new ResourceReader(); } } } }