Monorail study Note 3: easy to use and powerful routing functions

Source: Internet
Author: User
We often see this URL when browsing the forum or blog: (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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.