Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to System.web.ui.page

I have an ASP.Net application and I've noticed through using profilers that there is a sizable amount of processing that happens before my page even runs. In my application, we don't used viewstate, asp.Net session, and we probably don't require most of the overhead that comes of a consequence of using the asp.net page lifecycle. Is there some other class I can easily inherit from that will cut out all the Asp.Net stuff, and just let my handle writing to the page by myself?

I've heard that ASP.Net MVC can cut down page loads considerably, simply because it doesn't use the old asp.net lifecycle, and handles pages differently. Is there an easy way, maybe by simply having my web pages inherit some other class to take advantage of something like this. I would like a solution that works in ASP.Net 2.0 if at all possible.

like image 460
Kibbee Avatar asked Feb 25 '09 15:02

Kibbee


People also ask

What is system web UI page?

System.Web.UI.Page is .net framework class library, which is responsible to make your file as aspx, and handle request, response to server. It helps us to create our own page which works like aspx page and handle all events.

What are the different approaches to building modern web UI?

There are three general approaches to building modern web UI with ASP.NET Core: Apps that render UI from the server. Apps that render UI on the client in the browser. Hybrid apps that take advantage of both server and client UI rendering approaches.

What will happen if I use system web UI without event?

Without System.Web.UI.Page your page will become bunch of text and will not handle any event. Please Sign up or sign in to vote. Refer to this link. It states that, System.Web.UI represents an .aspx file, also known as a Web Forms page, requested from a server that hosts an ASP.NET Web application.

What is ASP NET system WebUI?

System.Web.UI represents an .aspx file, also known as a Web Forms page, requested from a server that hosts an ASP.NET Web application. The Page class is associated with files that have an .aspx extension.


2 Answers

Most articles I found where talking about using the Page as a base class and implementing functionality on top of that, it looks like you need to make your own MyPage class that implements IHttpHandler

From the MSDN article


using System.Web;

namespace HandlerExample { public class MyHttpHandler : IHttpHandler { // Override the ProcessRequest method. public void ProcessRequest(HttpContext context) { context.Response.Write("This is an HttpHandler Test.");
context.Response.Write("Your Browser:"); context.Response.Write("Type: " + context.Request.Browser.Type + ""); context.Response.Write("Version: " + context.Request.Browser.Version); }

  // Override the IsReusable property.
  public bool IsReusable
  {
     get { return true; }
  }

} }

Again, from the article: To use this handler, include the following lines in a Web.config file.


<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
      </httpHandlers>
   </system.web>
</configuration>

I'd take a look at the source code for System.web.ui.page and take a look at what it does to guide you. My guess is that it mostly just calls the different methods in the asp.net page lifecycle in the right order. You'd do something similar by calling your own page_load from the ProcessRequest method. That would route to your individual implementation of your classes that implement your MyPage.

I've never thought of doing something like this before and it sounds pretty good since I really don't use any of the bloated webforms functionality. MVC may make this whole exercise futile, but it does seem pretty neat.

My Quick Example

new base:


using System.Web;
namespace HandlerExample
{
    // Replacement System.Web.UI.Page class
    public abstract class MyHttpHandler : IHttpHandler
    {
        // Override the ProcessRequest method.
        public void ProcessRequest(HttpContext context)
        {
            // Call any lifecycle methods that you feel like
            this.MyPageStart(context);
            this.MyPageEnd(context);
        }

    // Override the IsReusable property.
    public bool IsReusable
    {
        get { return true; }
    }

    // define any lifecycle methods that you feel like
    public abstract void MyPageStart(HttpContext context);
    public abstract void MyPageEnd(HttpContext context);

}

Implementation for the page:



// Individual implementation, akin to Form1 / Page1
public class MyIndividualAspPage : MyHttpHandler
{

    public override void MyPageStart(HttpContext context)
    {
        // stuff here, gets called auto-magically
    }

    public override void MyPageEnd(HttpContext context)
    {
        // stuff here, gets called auto-magically
    }
}

}

like image 113
Allen Rice Avatar answered Sep 21 '22 09:09

Allen Rice


If you don't need all this "asp.net stuff", you may wish to implement a custom IHttpHandler. Afaik, there are no other standard IHttpHandlers to reuse except the Page class.

like image 33
amartynov Avatar answered Sep 24 '22 09:09

amartynov