如何实现TextBox.Text spring.net AOP的建议切入点之前?

时间:2014-07-02 07:13:03

标签: c# asp.net spring-aop spring.net

我是Spring.NET的新手,想拦截ASP.NET中的TextBox.Text,以便将值设置为Textbox是HTMLEncoded。

我在web.config中的设置:

<configSections>
<!-- Spring for AOP-->
<sectionGroup name="spring">
  <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
  <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
  <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
</sectionGroup>

    

  <object id="myServiceObject" type="Spring.Aop.Framework.ProxyFactoryObject">
    <property name="target">
      <object id="myServiceObjectTarget" type="System.Web.UI.WebControls.TextBox"/>
    </property>
    <property name="interceptorNames">
      <list>
        <value>beforeAdvice</value>
      </list>
    </property>
  </object>
 <httpModules>
  <add name="SpringModule" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<httpHandlers>
  <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
</httpHandlers>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
  <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</modules>
<handlers>
  <add name="SpringPageHandler" verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
  <add name="SpringContextMonitor" verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/>
</handlers>

我的班级实施:

namespace BAY.KOL.WebSite.Aspects{

[Serializable]
public class HtmlEncodeBeforeAdvice : IMethodBeforeAdvice
{

    public void Before(MethodInfo method, Object[] args, Object target)
    {
        if (args.Length > 1 && args[0] != null)
        {
            args[0] = HttpUtility.HtmlEncode(args[0]);
        }
    }
}

然而,我无法取得成果。在调试期间,我发现Advice Class不会被调用一次。我错过了什么或完全走错了路。

0 个答案:

没有答案