473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.RewritePath but as far as I can understand this requires a
physical file to exist.

Can anyone help?

Thanks

Nov 23 '05 #1
6 5705
Hi,

there are two things needed here.

Context.RewritePath 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.LoadControl.

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.LoadControl 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>template1.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_BeginRequest and the rewrite will
always take the form
Context.RewritePath("~/masterpage.aspx","","requestedPage=requestedPage&o rig
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.googlegr oups.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.LoadControl 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>template1.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.googlegr oups.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
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
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...
0
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...
3
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...
3
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...
0
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: ...
2
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...
1
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.