Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, there is, but it is not easy and may not be worth your trouble.</p> <p>One way of doing it is to create your own BuildProvider and replace the default System.Web.Compilation.PageBuildProvider with it in the config file:</p> <pre><code>&lt;compilation debug="true"&gt; &lt;buildProviders&gt; &lt;add extension=".aspx" type="MyProject.MyPageBuildProvider" /&gt; &lt;/buildProviders&gt; &lt;/compilation&gt; </code></pre> <p>You would also create your own PageParser, most likely inherited from the TemplateParser. The BuildProvider is responsible for supplying the PageParser. In most primitive situation you could overwrite the ParseFile method, read the ASPX file, process it, create a copy and pass it to the base method.</p> <p>Unfortunately, all ASPX parsing code is sealed and internal to MS libraries, so you can't inherit. Rewriting it would mean building entire compilation engine.</p> <p>The alternative method is to create your own page builder and put it in the attribute. The drawback is that you get an easy access to literals (all your spaces etc) of the first level (the page) only. To get to inner controls and their literals, you have to either hack the parser using reflection or (proper) manipulate the code dom. This way you would get properly built .cs files and temporary assemblies.</p> <p>Here is a simplified sample:</p> <pre><code>namespace MyProject { [FileLevelControlBuilder(typeof(MyPageBuilder))] public partial class _Default : System.Web.UI.Page { //this is Default.aspx } //The builder of the page public class MyPageBuilder : FileLevelPageControlBuilder { //This is where you'd strip white space, but only of top level, //such as between the head and form, or form and the end of file public override void AppendLiteralString(string text) { //let's replace some white spaces with garbage base.AppendLiteralString(text.Replace(" ", "#").Replace("\t", "@").Replace("\r", "$").Replace("\n", "%")); } //Here you can manipulate the entire generated code using CodeDom public override void ProcessGeneratedCode(System.CodeDom.CodeCompileUnit codeCompileUnit, System.CodeDom.CodeTypeDeclaration baseType, System.CodeDom.CodeTypeDeclaration derivedType, System.CodeDom.CodeMemberMethod buildMethod, System.CodeDom.CodeMemberMethod dataBindingMethod) { base.ProcessGeneratedCode(codeCompileUnit, baseType, derivedType, buildMethod, dataBindingMethod); } //Alternatively, you can "hack" the PageParser here using reflection //However, the _text field at this point is irrelevant, so it can't be used public override void Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, string tagName, string ID, System.Collections.IDictionary attribs) { FieldInfo fi = parser.GetType().BaseType.BaseType.BaseType.GetField("_text", System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); string s = (string) fi.GetValue(parser); fi.SetValue(parser, s.Replace("\t", "*")); base.Init(parser, parentBuilder, type, tagName, ID, attribs); } } } </code></pre> <p>In my opinion, it is not worth the effort.</p> <p><strong>edited</strong> typo</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload