Friday, April 8, 2011

C#: PageParserFilter and ProcessCodeConstruct

I am trying to prevent user controls from having and <% ... %> on them. I have sub-classed PageParserFilter in an attempt to use the ProcessCodeConstruct() method to detect when a code block is being parsed and cause an error. Using the debugger I was able to see that the other methods of my overriden PageParserFilter are being called as intended, but ProcessCodeConstruct is not. Any idea when ProcessCodeConstruct is being called? If not, is there another way to accomplish what I'm trying to do?

From stackoverflow
  • Why are you trying to limit the functionality of User Controls? I for one find it convient to use <%,,,%> in script blocks to get the client id. Just curious whats your reasoning.

    Moskie : Coworker of poster here. The situation is we have people in our company that we want to be able to access and edit user controls, but we want them to only have the ability to do certain things. Hence, the PageParserFilter...
  • Why do you want ProcessCodeConstruct to be called?
    I think it should be related to setting the value of AllowCode.

    Moskie : AllowCode seems to disallow the use of (asp.net server) controls, right? Those should be allowed, while asp.net expressions and scripts are not...
    shahkalpesh : I think AllowCode will call ProcessCodeConstruct. In ProcessCodeConstruct, you can check for code type & return true/false depending on what you want. Again, this is my guess looking at docs/reflector.
    Kevin Albrecht : That was what we thought to, but it seems not to be the case.
  • It turns out that ProcessCodeConstruct is only called when the page is first compiled. We got it to work as intended.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.