TAILIEUCHUNG - ASP.NET 4 Unleased - p 118
Trong trường hợp này, mặc định cung cấp là "thuốc nổ" thể loại. Các trang mục tiêu không cần phải biết rằng nó đã được gọi với một giá trị mặc định, nó chỉ đơn giản là có thể lấy tên thể loại từ điển RouteData. | 1144 CHAPTER 25 Using the URL Routing Engine In the following route configuration we have a category browser page that we can reach with the category name route pattern. If the user doesn t supply a category name we supply a default URL pattern with defaults category-browse category categoryname - true new RouteValueDictionary categoryname explosives In this case the default supplied is the explosives category. The target page doesn t need to know that it was invoked with a default value it can simply grab the category name from the RouteData dictionary. Supplying defaults is useful both for creating default landing options for hitting pages without parameters but also so that the target page doesn t need to be cluttered up with conditional statements checking to see whether particular values have been supplied in route data. Using Constrained Routes For a lot of situations the type of route patterns that we have discussed thus far are sufficient. If you want static routes or routes with simple parameters with or without defaults you are all set. However if you want to further constrain your route patterns so that only after certain conditions are met should your route be invoked you re also in luck. One of the overloads of the MapPageRoute method that we haven t yet discussed actually takes a dictionary of constraints to route parameters. These constraints come in the form of regular expressions. We warned you earlier that we d have to talk about them eventually. At their simplest level you can use these regular expressions to limit the size of parameters so that when passing a state code on the URL the code must be only two characters and must not contain numbers. Anyone familiar with regular expressions also knows that you can create incredibly powerful expressions that do far more than just simple validation. Regular expressions are outside the scope of this book so we re going to use some simple expressions to .
đang nạp các trang xem trước