I need a good solution ASAP!

  • Thread starter Thread starter Chad A. Beckner
  • Start date Start date
C

Chad A. Beckner

I am (and have been trying!) to find a good way to do the following few
things:

1. When a user requests a .aspx/.htm/.html file, the file needs to be
automatically integrated into a page template. In ASP.NET, how can I do
this?
2. I know I can put custom controls, map .htm/.html files to utilize custom
controls, etc, but I don't want to go through and update 2000 pages (and
growing) to .aspx files and then add the controls.

Basically, I want to send .aspx/.htm/.html files to a "site template" page,
or control (but which?). If I use either, how can I a) integrate the server
controls properly; b) load the contents of the page they requested into my
site template file? I was able to do all this with .ASP using an ISAPI
filter to intercept the requests and change the path of the request to (for
example) site_template.asp. Any ideas and thoughts would be very much
appreciated.

And yes, I've tried googling asp.net template, and many other queries, but
99% of them refer to utilizing web controls. I need this also interact with
..htm/.html files in the most efficient manner possible.

Thanks for any help!

Chad
 
Check out the next version of ASP.Net (code name "Whidbey") which includes
"Master Pages" - very similar to what you're describing.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
i think you can make a HttpHandler to map the request
and create the content on demand.
for more detail about httpandler, please prefer msdn
 
I know that Whidbey will do this, but I can't wait until 2005! :-) I've
checked out some HTTP Handlers, and I've added a line to my Global.asax file
(see below) that will route requests to "something". The question from here
is, in this "something", such as an aspx or ascx file, how can I "execute"
the page the user actually requested?

Ugh, there has got to be a better way to templating files in ASP.NET!!
Thoughts?

Chad
 
Chad A. Beckner said:
I am (and have been trying!) to find a good way to do the following few
things:

1. When a user requests a .aspx/.htm/.html file, the file needs to be
automatically integrated into a page template. In ASP.NET, how can I do
this?
2. I know I can put custom controls, map .htm/.html files to utilize custom
controls, etc, but I don't want to go through and update 2000 pages (and
growing) to .aspx files and then add the controls.

I'm afraid you're not going to get a canned solution for this very soon. The
next version of ASP.NET would help you, but it's not even in beta yet.

It's possible that some of the solutions you found under "asp.net template"
would work for you even with the .htm files. If you set the IIS script
mappings such that .htm files are processed by aspnet_isapi.dll the same as
..aspx files are, then even .htm files will be able to pass through any
HttpHandler or HttpModule you may have.
 
I guess my next question would be: How can I "read" the content of the
requested file, the integrate it into my .aspx/ascx file, then have the file
compile/execute?

Chad
 
Chad A. Beckner said:
Got any good examples? How can I create the content on demand?

One very simple way to do this would be to create the .pdf file on the
server, but then have the page send it to the client via Response.WriteFile.
 
Chad A. Beckner said:
I guess my next question would be: How can I "read" the content of the
requested file, the integrate it into my .aspx/ascx file, then have the file
compile/execute?

Your handler can use Request.Url to see what file was requested, then
Server.MapPath to find out where it is on disk, then you can read it just
like any other file.

Actually, in this case, you might consider creating a "template" page which
contains an <iframe runat="server" />. Have your handler use
Context.RewritePath to change the path to
template.aspx?page=<originalRequestedHtml>. template.aspx could then set the
src attribute of the iframe to the <originalRequestedHtml>. I seem to recall
that I did that once to put a .pdf file inside of a template page.
 
another solution, as to the request, you can resolve the request and using
Response.WriteFile(Server.Mappath("filepath")) to response the content of
your html file content to the client, still using Httphandler technology to
handler all the request from client and processing it in a class
 
Will this method, Response.WriteFile(Server.Mappath("filepath")), work with
..aspx files also?

Chad
 
no , this methold ony apply to the static html or text content.
to .aspx files you can dispatch the request directly to the .aspx files

i think you must to have a .aspx template ,then the basepage.cs is a good
solution for you, you create serval server control for the common content,
and load the controls in your base page. all the exists .aspx.cs extend from
this basepage.cs
 
Ok, let me see if I'm understanding all this correctly:

1. Add verb to Web.config to route all .htm files to an aspx file. In
there, I will load the base class(es) and use
Response.WriteFile(Server.Mappath("filepath")) (should this go in the code
behind, or how would I do this without putting inline code in the HTML?)
2. Set up all .aspx files to inerit the base class .vb (or .cs) file.

Also, do you (or anyone) know of a way to not include the
<head></head><body></body> tags when the .aspx file is loading the "child"
aspx file controls?

Chad
 
Chad A. Beckner said:
Will this method, Response.WriteFile(Server.Mappath("filepath")), work with
.aspx files also?

No, but I believe that the <iframe> method might work. You'd have to be
careful that your handler doesn't recurse!
 
I'm not necessary worried about .pdf files, more about .htm/.html and aspx
files. I want to "invisibly" template the page, not use a querystring setup
(such as you mentioned of template.aspx?page=<originalRequestedHtml>. I
would like for everything to appear "transparently", but also load up the
controls and other content properly. Also, I don't want to have to worry
about the darn <html><head></head><body></body></html> problems. When the
..htm files are uploaded to the server, I don't want to have to remove those
on every page every time they are uploaded/updated.

Ideas?

(Thanks!)

Chad
 
to htm files, you can directly response.WriteFile()
to aspx files ,you can can use basepage inherited by other aspx.cs file
 
In that case, I think you'll have to write your own HttpHandler. The down
side is, it may take awhile to design and build it. The upside is, you have
total control over how it operates.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Chad A. Beckner said:
I'm not necessary worried about .pdf files, more about .htm/.html and aspx
files. I want to "invisibly" template the page, not use a querystring setup
(such as you mentioned of template.aspx?page=<originalRequestedHtml>. I
would like for everything to appear "transparently", but also load up the
controls and other content properly. Also, I don't want to have to worry
about the darn <html><head></head><body></body></html> problems. When the
.htm files are uploaded to the server, I don't want to have to remove those
on every page every time they are uploaded/updated.

The query string will not be visible to your users. This is a server-side
URL rewrite.
 
Back
Top