Do i loose the power of asp.net if i use a custom extension (not .aspx) with IHttpHandlerFactory

Discussion in 'ASP .Net' started by Hope Paka, Jun 10, 2005.

  1. Hope Paka

    Hope Paka Guest

    I want to use my custom url extension instead of .aspx. I can achieve this
    by writing a custom handler that implements the IHttpHandlerFactory.
    In the GetHandler method of the IHttpHandlerFactory i want to construct a
    Page class instance and load my other controls to it and return the page
    instance.
    This is what .net framework does. There is a small difference what i am
    thinking and the .net framework has done. .Net Framework calls the
    PageParser.GetCompiledPageInstance() methot to take the page from the cached
    content. In my implemention, instance of the Page class is created and it is
    returned.

    Ex:

    PageHandlerFactory
    public virtual IHttpHandler GetHandler(HttpContext context, string
    requestType, string url, string path)
    {
    InternalSecurityPermissions.UnmanagedCode.Assert();
    return PageParser.GetCompiledPageInstanceInternal(url, path, context);
    }

    <add verb="*" path="*.umut" type="MyOwnHandlerFactory"/>
    MyOwnHandlerFactory
    public virtual IHttpHandler GetHandler(HttpContext context, string
    requestType, string url, string path)
    {
    Page page = new Page

    page.Controls.Add ( new System.Web.UI.LiteralControl
    ("<html><head></head><body>");
    System.Web.UI.HtmlControls.HtmlForm form = new
    System.Web.UI.HtmlControls.HtmlForm ()
    form.Name = "Form1";
    form.Method = "Post";
    page.Controls.Add (form);
    Control c1 = page.LoadControl (ABC.ascx);
    form.Controls.Add (c1);
    page.Controls.Add ( new System.Web.UI.LiteralControl ("</body><html>");
    return page.
    }

    I have described what the .net framework does and the one in my mind. I am
    still using the framework but only i have different extension.
    As a summary:

    1) Do i loose the cache functionality of the PageParser. (May be it is
    not necessary because i am only parsing UserControls with page.LoadControl)
    2) Can i use everthing that asp.net supports like Session, ViewState
    etc?
     
    Hope Paka, Jun 10, 2005
    #1
    1. Advertising

  2. Hope Paka

    Brock Allen Guest

    Why go to all that work? Just register in web.config your custom handler
    and map it onto the existing ASPX handler:

    <configuration>
    <system.web>
    <httpHandlers>
    <add verb="*" path="*.umut" type="System.Web.UI.PageHandlerFactory"/>
    </httpHandlers>
    </system.web>
    </configuration>

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > I want to use my custom url extension instead of .aspx. I can achieve
    > this
    > by writing a custom handler that implements the IHttpHandlerFactory.
    > In the GetHandler method of the IHttpHandlerFactory i want to
    > construct a
    > Page class instance and load my other controls to it and return the
    > page
    > instance.
    > This is what .net framework does. There is a small difference what i
    > am
    > thinking and the .net framework has done. .Net Framework calls the
    > PageParser.GetCompiledPageInstance() methot to take the page from the
    > cached
    > content. In my implemention, instance of the Page class is created and
    > it is
    > returned.
    > Ex:
    >
    > PageHandlerFactory
    > public virtual IHttpHandler GetHandler(HttpContext context, string
    > requestType, string url, string path)
    > {
    > InternalSecurityPermissions.UnmanagedCode.Assert();
    > return PageParser.GetCompiledPageInstanceInternal(url, path,
    > context);
    > }
    > <add verb="*" path="*.umut" type="MyOwnHandlerFactory"/>
    > MyOwnHandlerFactory
    > public virtual IHttpHandler GetHandler(HttpContext context, string
    > requestType, string url, string path)
    > {
    > Page page = new Page
    > page.Controls.Add ( new System.Web.UI.LiteralControl
    > ("<html><head></head><body>");
    > System.Web.UI.HtmlControls.HtmlForm form = new
    > System.Web.UI.HtmlControls.HtmlForm ()
    > form.Name = "Form1";
    > form.Method = "Post";
    > page.Controls.Add (form);
    > Control c1 = page.LoadControl (ABC.ascx);
    > form.Controls.Add (c1);
    > page.Controls.Add ( new System.Web.UI.LiteralControl
    > ("</body><html>");
    > return page.
    > }
    > I have described what the .net framework does and the one in my mind.
    > I am
    > still using the framework but only i have different extension.
    > As a summary:
    > 1) Do i loose the cache functionality of the PageParser. (May be
    > it is
    > not necessary because i am only parsing UserControls with
    > page.LoadControl)
    > 2) Can i use everthing that asp.net supports like Session,
    > ViewState
    > etc?
     
    Brock Allen, Jun 10, 2005
    #2
    1. Advertising

  3. That's entirely correct.

    I'd also map the extension in the Application's "Configuration"
    section in the "Virtual Directory" tab of the IIS MMC.

    If using ASP.NET 2.0, he'd also need to add:

    <compilation>
    <buildProviders>
    <add extension=".umut" appliesTo="Web" type="System.Web.Compilation.PageBuildProvider" />
    </buildProviders>
    </compilation>




    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en EspaƱol
    Ven, y hablemos de ASP.NET...
    ======================

    "Brock Allen" <> wrote in message news:...
    > Why go to all that work? Just register in web.config your custom handler
    > and map it onto the existing ASPX handler:
    >
    > <configuration>
    > <system.web>
    > <httpHandlers>
    > <add verb="*" path="*.umut" type="System.Web.UI.PageHandlerFactory"/>
    > </httpHandlers>
    > </system.web>
    > </configuration>
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen




    >> I want to use my custom url extension instead of .aspx. I can achieve
    >> this
    >> by writing a custom handler that implements the IHttpHandlerFactory.
    >> In the GetHandler method of the IHttpHandlerFactory i want to
    >> construct a
    >> Page class instance and load my other controls to it and return the
    >> page
    >> instance.
    >> This is what .net framework does. There is a small difference what i
    >> am
    >> thinking and the .net framework has done. .Net Framework calls the
    >> PageParser.GetCompiledPageInstance() methot to take the page from the
    >> cached
    >> content. In my implemention, instance of the Page class is created and
    >> it is
    >> returned.
    >> Ex:
    >>
    >> PageHandlerFactory
    >> public virtual IHttpHandler GetHandler(HttpContext context, string
    >> requestType, string url, string path)
    >> {
    >> InternalSecurityPermissions.UnmanagedCode.Assert();
    >> return PageParser.GetCompiledPageInstanceInternal(url, path,
    >> context);
    >> }
    >> <add verb="*" path="*.umut" type="MyOwnHandlerFactory"/>
    >> MyOwnHandlerFactory
    >> public virtual IHttpHandler GetHandler(HttpContext context, string
    >> requestType, string url, string path)
    >> {
    >> Page page = new Page
    >> page.Controls.Add ( new System.Web.UI.LiteralControl
    >> ("<html><head></head><body>");
    >> System.Web.UI.HtmlControls.HtmlForm form = new
    >> System.Web.UI.HtmlControls.HtmlForm ()
    >> form.Name = "Form1";
    >> form.Method = "Post";
    >> page.Controls.Add (form);
    >> Control c1 = page.LoadControl (ABC.ascx);
    >> form.Controls.Add (c1);
    >> page.Controls.Add ( new System.Web.UI.LiteralControl
    >> ("</body><html>");
    >> return page.
    >> }
    >> I have described what the .net framework does and the one in my mind.
    >> I am
    >> still using the framework but only i have different extension.
    >> As a summary:
    >> 1) Do i loose the cache functionality of the PageParser. (May be
    >> it is
    >> not necessary because i am only parsing UserControls with
    >> page.LoadControl)
    >> 2) Can i use everthing that asp.net supports like Session,
    >> ViewState
    >> etc?

    >
    >
    >
     
    Juan T. Llibre, Jun 10, 2005
    #3
  4. Hope Paka

    Hope Paka Guest

    I know that, but i dont want lots of .aspx files. I am developing a control.
    Instead of it, my consumers use .ascx user controls.
    That is why i am tring to create Page instance on the fly.

    "Brock Allen" <> wrote in message
    news:...
    > Why go to all that work? Just register in web.config your custom handler
    > and map it onto the existing ASPX handler:
    >
    > <configuration>
    > <system.web>
    > <httpHandlers>
    > <add verb="*" path="*.umut" type="System.Web.UI.PageHandlerFactory"/>
    > </httpHandlers>
    > </system.web>
    > </configuration>
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >> I want to use my custom url extension instead of .aspx. I can achieve
    >> this
    >> by writing a custom handler that implements the IHttpHandlerFactory.
    >> In the GetHandler method of the IHttpHandlerFactory i want to
    >> construct a
    >> Page class instance and load my other controls to it and return the
    >> page
    >> instance.
    >> This is what .net framework does. There is a small difference what i
    >> am
    >> thinking and the .net framework has done. .Net Framework calls the
    >> PageParser.GetCompiledPageInstance() methot to take the page from the
    >> cached
    >> content. In my implemention, instance of the Page class is created and
    >> it is
    >> returned.
    >> Ex:
    >>
    >> PageHandlerFactory
    >> public virtual IHttpHandler GetHandler(HttpContext context, string
    >> requestType, string url, string path)
    >> {
    >> InternalSecurityPermissions.UnmanagedCode.Assert();
    >> return PageParser.GetCompiledPageInstanceInternal(url, path,
    >> context);
    >> }
    >> <add verb="*" path="*.umut" type="MyOwnHandlerFactory"/>
    >> MyOwnHandlerFactory
    >> public virtual IHttpHandler GetHandler(HttpContext context, string
    >> requestType, string url, string path)
    >> {
    >> Page page = new Page
    >> page.Controls.Add ( new System.Web.UI.LiteralControl
    >> ("<html><head></head><body>");
    >> System.Web.UI.HtmlControls.HtmlForm form = new
    >> System.Web.UI.HtmlControls.HtmlForm ()
    >> form.Name = "Form1";
    >> form.Method = "Post";
    >> page.Controls.Add (form);
    >> Control c1 = page.LoadControl (ABC.ascx);
    >> form.Controls.Add (c1);
    >> page.Controls.Add ( new System.Web.UI.LiteralControl
    >> ("</body><html>");
    >> return page.
    >> }
    >> I have described what the .net framework does and the one in my mind.
    >> I am
    >> still using the framework but only i have different extension.
    >> As a summary:
    >> 1) Do i loose the cache functionality of the PageParser. (May be
    >> it is
    >> not necessary because i am only parsing UserControls with
    >> page.LoadControl)
    >> 2) Can i use everthing that asp.net supports like Session,
    >> ViewState
    >> etc?

    >
    >
    >
     
    Hope Paka, Jun 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Ter-Saakov

    If i am changing aspx file will i loose session?

    George Ter-Saakov, Aug 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    442
    Krissy
    Aug 15, 2003
  2. SStory
    Replies:
    2
    Views:
    365
    SStory
    Oct 16, 2003
  3. =?Utf-8?B?QmFydG9zeiBLcnp5d2lja2k=?=

    IHttpHandlerFactory and Session problem !

    =?Utf-8?B?QmFydG9zeiBLcnp5d2lja2k=?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    606
    Vadim Chekan
    Jul 1, 2004
  4. stillworkingfortheman
    Replies:
    0
    Views:
    357
    stillworkingfortheman
    Oct 19, 2006
  5. Replies:
    8
    Views:
    396
    Mark Dickinson
    Apr 17, 2008
Loading...

Share This Page