locked
WebPages effectiveness in deep RRS feed

  • Question

  • User1065418170 posted

    I just played with WebPages (Razor2) website project template and figured out how its really works. I noticed that there is a "hidden" background generated C# class (eg.: _Page_Default_cshtml) which created by the engine. This class inherited from WebPage and contains an Execute overriden method which produces the output. This concept basicly looks good but when I look at the code inside the generated Execute function I became little dissapointed! Its actually generetes a lot of WriteLiteral statements filled by strings copied from original cshtml file. Is this trully the best approach to process every request? 

    As I see now this WebPages technique translates all off the html codes into PRINT statements and generates new html code as response. I think this not so effective. Developer writes a html code -> engine creates a class -> class creates a html output line-by-line. OMG!

    I'm a developer so this approach means to me its better to write my own Execute function to generate html output without cshtml files but directly from my controllers (database, flatfile etc). As I digged deeper I also noticed that I cannot override generated class so I no chance to change processing steps in general way. 

    My question is, is it possible to create my custom class inhertied from WebPage and then skip background generated class which automatically inherited from my own WebPage class in default way? Its clear to me that I can creat my own class and set @inherits keyword to that in cshtml files but finally the automatically generated class always override my own Execute processing. 

     

     

     

    Wednesday, September 26, 2012 5:07 AM

Answers

  • User753101303 posted

    Hi,

    And this is basically what your own code would do that is to write HTML markup to the response Stream you are sending to the browser? Basically Razor is just a syntax that ease mixing HTML markup and server code (this is NOT just html) rather than writing C# and using Response.Write explicitely to output the HTML markup you want.

    So basically the principle stays the same expect that you'll see this C# code rather than being focused on the HTML markup you want to render.

    This is true as well for all dynamic pages technologies. Ultimately you have some server code (written by you or generated for you) that writes HTML markup to the browser.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 2, 2014 7:26 AM