Programmatically creating pages

G

Guest

Is there a way to instantiate a page object in code and redirect the response to it? I know that this is how the actual ASP.NET engine ultimately does it under the covers. However, is this available to the developer? I want to be able to use page inheritance to create a centralized page controler without the need to build .aspx files for every page (since they would be pretty much empty shells anyway).

Here is a sample of what I "want" to do. However, the Response.Redirect() method currently only takes a string argument and does not accept a page object reference

MyPage myPage = new MyPage()
Response.Redirect(myPage); <---- this does not work. I wish that it would

Any ideas
Thanks
Matt
 
P

Peter Rilling

Probably not since there is a lot more then creating a page instance, such
as creating a request and response object for the page, extracting cookies,
parsing querystrings, etc. Might as well write your own web server.

Question, with your desired behavior, how is the browser going to get the
HTML content. Unless you page objects stream the content through the
Response.Write method, you pages will not be able to display since the
code-behind does not contain the actual markup. You say that you do not
want any ASPX files, but that is where the markup is located.

If you want, you can create a sight with no ASPX files at all but rather use
an HttpHandler to intercept any ASPX calls which could then stream the
desired markup to the browser.

mslyh said:
Is there a way to instantiate a page object in code and redirect the
response to it? I know that this is how the actual ASP.NET engine ultimately
does it under the covers. However, is this available to the developer? I
want to be able to use page inheritance to create a centralized page
controler without the need to build .aspx files for every page (since they
would be pretty much empty shells anyway).
Here is a sample of what I "want" to do. However, the Response.Redirect()
method currently only takes a string argument and does not accept a page
object reference.
 
E

Eran Amitai

Matt,

If your .aspx file would only be empty shells (i.e. no meaningful HTML) then
you don't need pages. Instead of actual pages create a lot of different
classes (one for each page you would have created with the logic specific to
that "page") derived from one of Control, WebControl, UserControl, or
similar classes.

Instead of redirecting to another page you controler class needs to
instantiate the appropriate control class and let it process (probably need
to add it to the controller object's Controls collection).

Eran


mslyh said:
Is there a way to instantiate a page object in code and redirect the
response to it? I know that this is how the actual ASP.NET engine ultimately
does it under the covers. However, is this available to the developer? I
want to be able to use page inheritance to create a centralized page
controler without the need to build .aspx files for every page (since they
would be pretty much empty shells anyway).
Here is a sample of what I "want" to do. However, the Response.Redirect()
method currently only takes a string argument and does not accept a page
object reference.
 
M

matt

To achieve what you are looking for you need to look at Context.Rewritepath
method and an HttpModule to pass control of the request to the page that you
specify in the rewritepath method. see
http://msdn.microsoft.com/library/d...systemwebhttpcontextclassrewritepathtopic.asp

We have a Content management system
http://www.3internet.co.uk/products/inigo.aspx that does exactly what you
mention using this method. A site using our cms typically uses less than 10
templates to serve all page content, when the page is requested the path
relates to content stored in sql database which also contains details of
which template to use. In the HttpModule the request is then forwarded
using the Context.Rewritepath method to the template specified. This has
the big added bonus of allowing pages to be served without the need for
lengthy querystrings, all pages having static looking urls, which really
does make a difference in search engine positioning.

Good Luck

Matt
http://www.3internet.com
 
G

Guest

Thanks to all that answered. There were some really great ideas presented and many of them will actually acomplish what I want to do. I will do some more research on the implications of each method to decide which one will be best in my situation

Thanks again for all of the great options
Mat
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top