views:

72

answers:

2

I know why runat="server" is currently required (ASP.NET why runat="server"), but the consensus is that it should not be required if you incorporate a simple default into the design (I agree of course).

Would it be possible to modify, extend, decompile and recreate, intercept or otherwise change the behavior of how ASP.NET parses ASPX and ASCX files so that runat="server" would no longer be required? For instance, I assume that a version of Mono could be branched to accomplish this goal.

In case specific requirements are helpful, the following highlights one design:

  • During parsing, when configured namespace tags are encountered (such as "asp"), default the element's runat property to "server"
  • During parsing, when configured namespace tags are encountered (such as "asp"), if the element's runat property value is available, then that value should be used in place of the default
  • New page-level setting introduced (can be set in the page directive or web.config) that specifies the default runat value for a specific namespace tag
A: 

So far as I know, there are no hooks deep enough in the ASP.NET Page handling process that would allow this. I know of no way to override or extend the parsing or processing of actual aspx/ascx code.

While ASP.NET is fairly flexible and lets your override many default behaviors (like how ViewState is saved/loaded, where Session is stored, etc) this is not one of them.

However... technically the Page object is just another HttpHandler. You could write your handler and do anything you wanted with it. All you have to do is implement everything the Page class does and then throw in this extra functionality. :) Alternately, pull out Reflector and dig through the Page object's ProcessRequest method and see where it is actually parsing/initializing the objects declared in aspx and you might get a clue how to implement the functionality you're looking for. But I suspect you'd be wasting your time.

Bryan
A: 

I'm afraid you'd have to modify the entire page parser to accomplish this, and I don't think that's possible.

On the other hand, you should be able to create your own. See the buildProviders Element and the BuildProvider class. You should be able to create your own build provider for .aspx pages and use it to replace the built-in provider.

Unfortunately, the PageBuildProvider class used by ASP.NET is internal, and the PageParser class that it uses to parse pages is sealed. You'll be entirely on your own.

Consider that runat="server" has been in ASP.NET for a decade now, and I think you'll see that this won't change anytime soon.

You'd also lose Designer support, but maybe you don't care about that.

John Saunders
Right, not very concerned with Designer support.. So would you agree that if the PageParser and PageBuildProvider classes were decompiled and re-assembled into a new project / modified, that would likely work? I know that's probably not legal due to the [Microsoft .NET Framework Redistributable EULA](http://msdn.microsoft.com/en-us/library/ms994405.aspx), but I was wondering if that would be the case in theory. Thanks
sean2078