We often see this URL when browsing the forum or blog: http://www.cnblogs.com/firstyi/archive/2007/10/17/927967.html (this is a chain in the blog, its real existence is not 927967.html this file, are escaped through routing
Therefore, we can conveniently implement this function in monorail.
First, configure in Web. config: < Monorail >
< Routing >
< Rule >
< Pattern > (/Blog/posts/) (\ D +)/(\ D +) (.) HTML $ </ Pattern >
< Replace > <! [CDATA [ /Blog/view. rails? Year = $2 & month = $3 ]> </ Replace >
</ Rule >
</ Routing >
</ Monorail >
< System . Web >
< Httpmodules >
< Add Name = "Routing" Type = "Castle. Monorail. Framework. routingmodule, Castle. Monorail. Framework" />
</ Httpmodules >
</ System. Web >
That is, monorail provides the routingmoudle class for processing.
Then we can directly enter http: // localhost: *****/blog/posts/11/22 .html in the browser to browse, the system will automatically call/blog/view in the background during browsing. rails? Year = 11 & month = 22 page
(Note: $1 =/blog/posts/, the value in each () will be replaced with a parameter)
Then the following is relatively simple.
Add methods to controllers/blogcontroller. CS:(BolgcontrollerSmartdispatchercontrollerInheritance)
Public Void View ( Int Year, Int Month)
{< br>
propertybag. add ( " year " , year );
propertybag. add ( " month " , month );
}
Add view. VM file under views/blogBlog content:<BR>
Blog yearIs$ Year<BR>
Blog monthIs$ Month
The final browsing result is:Blog content:
Blog yearIs 11
Blog monthIs 22
of course, this is just a simple example, with no practical effect. However, on this basis, we can implement many other functions.