473,699 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTPModule/HTTPHandler to process request

Hi there,

I'm trying to create a new website that will have a common aspx file
serve as a template. I want all other pages to use this file and
'inject' their own content i.e. user controls, static html etc. The
thing is that I don't actually want these other 'pages' to exist on
disk (since I don't want to have to maintain multiple aspx pages - just
the content). I basically want an XML file that defines the content
'page' path, template file and the actual content. This XML file will
serve as the configuration for the whole process.

The other thing that I want to do is make sure that all of my pages
have friendly URLs i.e. an entry in the XML file with a page path such
as /test.aspx will actually show in the browser as
http://www.mysite.com/test.aspx (even though the physical file does not
exist).

At the moment, I am able to capture a request (using HttpModule) to
this page and write the content of it to the Response object but I'm
not sure how to 'inject' the associated user controls.

I have seen this functionality in action but can't quite put my finger
on how to replicate it. I have also seen reference to using
Context.Rewrite Path but as far as I can understand this requires a
physical file to exist.

Can anyone help?

Thanks

Nov 23 '05 #1
6 5720
Hi,

there are two things needed here.

Context.Rewrite Path as you have noticed. In IIS you can set whether the
file which is being requested has to actually exist. I think for ASPX
this is turned of by default (meaning you can request some not existing
ASPX and ASP.NET will handle it) You will need your HttpModule and
rewrite the path to and actual existing page and pass along the data
found in the URL. For instance, rewrite www.mysite/test.asp to
www.mysite.default.aspx?page=test

Next in the default.aspx code you'll need to read this setting and load
the appropriate user controls. E.g. some kind of XML like:
<Pages>
<Page name='test'>
<Control id='myControl' filePath='~/control.ascx'/>
</Page>
</Pages>

You can load usercontrols using Page.LoadContro l.

Hope it helps,

Grtz, Wouter van Vugt
Trainer - Info Support - www.infosupport.com
www.dive-in-it.nl

Nov 23 '05 #2
Maybe you've already looked at this, so please excuse me if I'm stating the
obvious. I'm just looking to help ( and learn a thing or two too ;>)

Have you looked at the master pages in 2.0? Maybe you're using 1.1, in
which case I would strongly suggest looking at 2.0 for this feature alone!
It's worth the price of admission! If you are, maybe there was some other
bigger reason to avoid Master pages, which I missed (sorry).

Good luck.
Nov 23 '05 #3
Hi there,

Unfortunately, ASP.NET 2.0 master pages will only get around the
problem of the templates (and management has already pushed version 2
to phase three). This would still leave me with the problem of the
friendly URLs too.

Thanks for the help though!

Nov 24 '05 #4
Hi there,

Thanks for the help!

Unfortunately I don't think that this is quite what I was looking for.

I am already handling request for pages that don't physically exist and
am able to load their templates (see XML below). Another question here
though - can I load a Page object and pass it through to the Response?
The reason that I ask is that I am aware of the Page.LoadContro l method
but need a Page object to be able to perform this with. I have been
unable to work out how to pass this dynamically built page through to
the Response (remembering that the actual page that was requested
doesn't physically exist - only it's base template does and I don't
want its name appearing in the URL [see below]).

In your example of RewritePath your final URL is actually pointing to
http://www.mysite.com/default.aspx?page=test. I am looking for the
request to be for http://www.mysite.com/test.aspx and the URL to remain
as http://www.mysite.com/test.aspx.

<pages>
<page>
<path>test.aspx </path>
<templateFile>t emplate1.aspx</templateFile>
<content>
... various references to ascx files and some static html
</content>
</page>
</pages>

So for the example above, I would request
http://www.mysite.com/test.aspx and a Page would be constructed by
opening template1.aspx and loading the specified controls. It would
then be served AS http://www.mysite.com/test.aspx (even though this
file doesn't exist on disk).

I think that I am starting to come to the conclusion that I may need to
actually build this page and write it to disk and then RewritePath to
this newly created file. Is there another way to do it i.e. write a new
ASPX file to disk based on an existing ASPX and some user controls?!

Like I say, I have seen functionality like this before but only from
the front-end.

Thanks again

Nov 24 '05 #5
I haven't been following this thread, but the way I do this , and the way I
believe this is generally done is to create a single 'master page' ( just to
confuse things ;-) ) that handles all incoming page requests.
this page contains your basic site layout which includes one or more
placeholders for navigation, content etc. those content is determined at the
time of the request.
I do my url rewriting in Application_Beg inRequest and the rewrite will
always take the form
Context.Rewrite Path("~/masterpage.aspx ","","requested Page=requestedP age&orig
inalQueryString ")
then the master page would use the requestedPage parameter to determine what
page to build doing its grunt work in the Page.OnInit() method.

http://www.hgha.ca is an example of a website that uses this approach -
there is one and only one physical aspx on the server although it appears to
have 100+ pages when browsing. fyi, this lets users log in and modify the
content right online and in many places the content is extremely "amateur".
one additional point for this site , the .htm extension is mapped in IIS to
the aspnet process so that the user only sees .htm pages and no .aspx pages

Gerry


"Steve" <ma**@aimackay. me.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi there,

Thanks for the help!

Unfortunately I don't think that this is quite what I was looking for.

I am already handling request for pages that don't physically exist and
am able to load their templates (see XML below). Another question here
though - can I load a Page object and pass it through to the Response?
The reason that I ask is that I am aware of the Page.LoadContro l method
but need a Page object to be able to perform this with. I have been
unable to work out how to pass this dynamically built page through to
the Response (remembering that the actual page that was requested
doesn't physically exist - only it's base template does and I don't
want its name appearing in the URL [see below]).

In your example of RewritePath your final URL is actually pointing to
http://www.mysite.com/default.aspx?page=test. I am looking for the
request to be for http://www.mysite.com/test.aspx and the URL to remain
as http://www.mysite.com/test.aspx.

<pages>
<page>
<path>test.aspx </path>
<templateFile>t emplate1.aspx</templateFile>
<content>
... various references to ascx files and some static html
</content>
</page>
</pages>

So for the example above, I would request
http://www.mysite.com/test.aspx and a Page would be constructed by
opening template1.aspx and loading the specified controls. It would
then be served AS http://www.mysite.com/test.aspx (even though this
file doesn't exist on disk).

I think that I am starting to come to the conclusion that I may need to
actually build this page and write it to disk and then RewritePath to
this newly created file. Is there another way to do it i.e. write a new
ASPX file to disk based on an existing ASPX and some user controls?!

Like I say, I have seen functionality like this before but only from
the front-end.

Thanks again

Nov 24 '05 #6
Sorry I couldn't help more, but I'm reading the other responses to try to
learn (not having much luck at it though, I'm still too new, but I'll get
it! :>)

Good luck.


"Steve" <ma**@aimackay. me.uk> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi there,

Unfortunately, ASP.NET 2.0 master pages will only get around the
problem of the templates (and management has already pushed version 2
to phase three). This would still leave me with the problem of the
friendly URLs too.

Thanks for the help though!

Nov 24 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1580
by: Peter Rilling | last post by:
Can an HttpHandler or HttpModule be invoked on non-ASP.NET pages such as images or ASP or HTML pages? Can I trap a request for those pages? If not, how might I trap those requests?
1
1392
by: Juha Borenius | last post by:
I have a web site that requires some directories to be protected with password. Directories might contain any kind of files from aspx -pages to pdf -documents. Protected directories are not virtual directories - there's only one application. Protection must be controlled from program - so authentication methods provided by framework don't seem to work as there's only one web.config -> can't control each directory independently. I think...
0
1554
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our app has about 50 file extensions that we map in IIS and handle in our HTTPHandler to catch the reference and then lookup the correct content from a database. In addition, we do some magic in a HTTPModule to rewrite paths for file types we don't...
3
3756
by: Michael Iantosca | last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page class. If is attached I want to perform some action. How can I access custom attributes from an HttpModule? I have to pass a target to the System.Attribute.GetCustomAttribute() call to attempt to retrieve the attached attribute. I tried to access...
3
2125
by: MWells | last post by:
I'm having an issue getting my HttpHandlers and HttpModules to play together nicely. My HttpHandlers take special document types (defined by extension) and process them specially. I might have an HttpHandler installed to render Excel files as HTML, or to render TIFFs to JPEGs, etc. The HttpModules are used for Uri handling, so that a request for a resource like;
0
1174
by: tshad | last post by:
I am trying to get an HttpHandler I found on the Web to work. It is called FreeText. It allows fancy handling of a Textbox. This program is just a dll that you set up as an HttpHandler: <httpHandlers> <add verb="GET" path="FtbWebResource.axd" type="FreeTextBoxControls.AssemblyResourceHandler, FreeTextBox" />
2
4584
by: walter | last post by:
Hi there, I know there is pool of HttpApplications, and for each request coming in, HttpRuntime will dedicate one from pool to serve the request. My questions are : 1. since HttpModule is plug into the process, does each instance of HttpApplication keep its own set of HttpModule instance or HttpModules are shared among all HttpApplication instances? 2. In case of HttpApplication keep its own set of HttpModule, does the HttpModule...
1
1611
by: Max | last post by:
I have my HTTPModule or HTTPHandler registered to process all file types (*). I have IIS configured to pass all requests to ASP.NET for this virtual directory. In some cases depending on the request parameters I may decide that I need to yield this request and I want it to be processed as if my handler was not installed there and is if ASP.NET was configured to process only *.aspx files. Is there a relatively simple way to implement...
3
1588
by: Guzeppi | last post by:
if i want to create a redirection service, i.e. requests on a certain url are redirected to other urls depending on the querystring parameters in the request, what is best to use in this case httpmodule or httphandler? which gets executed first in the asp.net pipeline?
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7755
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.