Transformfilter is used for conversion. For example, it converts all the content on the page to uppercase or converts some keywords to hyperlinks. For example, we often see that some keywords in Blog content have been converted into hyperlinks, so we can use transformfilter to implement it. Transformfilter is executed before the page is actually rendered.
1. Replace lowercase letters with uppercase letters using ready-made classes:
Controller: [Transformfilter ( Typeof (Wikitransformfilter), executionorder = 1 ), Transformfilter ( Typeof (Uppercasetransformfilter), executionorder = 2 )]
Public Void Index ()
{
}
The transformfilter attribute is used, and then the wikitransformfilter and uppercasetransformfilter filters provided in monorail are used (under Castle. Monorail. Framework. transformfilters)
You can see that multiple transformfilters can be used for the same method, and executionorder specifies the execution sequence.
Note: The transformfilter attribute can only be used on methods and cannot be used on classes.
2. Define and use your own filter class
[Transformfilter ( Typeof (Mytransformfilter)]
Public Void Index ()
{
}
Class Mytransformfilter: transformfilter
{
Public Mytransformfilter (Stream basestream)
: Base (Basestream)
{
}
Public Override Void Write ( Byte [] Buffer, Int Offset, Int Count)
{
If (Closed) Throw New Objectdisposedexception ( " Mytransformfilter " );
String Content = Encoding. Default. getstring (buffer, offset, count );
Content = Content. Replace ( " Gspring " , " <A href = 'HTTP: // www.cnblogs.com/firstyi'> Yongchun pavilion </a> " );
Byte [] Output = Encoding. Default. getbytes (content );
Basestream. Write (output, 0 , Output. Length );
}
}
Defines a mytransformfilter that inherits from transformfilter and reloads the write method.
This class is used to replace the gspring that appears on all webpages with the link of my blog -_-