官术网_书友最值得收藏!

Summary

In real life, chances are you will mix code-based routing configuration and attributes. In our example, we will be using localization features, which require a lot of configuration, typically code-based configuration. Attribute routing also has its place, because we can directly define accessible endpoints that do not need to be restricted by general routing templates. Route constraints are very powerful and should be used.

It is always good to start with the included default route template and go from there. It should be sufficient for around 80% of your needs. Others will either be defined through a custom route or routing attributes.

We saw in this chapter that security is something that needs to be taken into account, and using routing attributes for this purpose seems ideal, as we can immediately see what the security restrictions are by looking at controller methods.

We've seen the different ways in which we can configure routing, in other words, turning browser requests into actions. We looked at code-based and attribute-based routing and learned about some of their strengths and limitations. We found out how we can restrict URL parameters to be of certain types or match certain requirements, as well as how to prevent an action method from being called unless it matches a specific verb, HTTPS requirement, or request content type. Finally, we looked at how to use routes to direct to status code or error specific actions so as to return friendly error pages.

Quite a few of the topics covered in this chapter will surface again in later chapters. In the next chapter, we will be talking about probably the most important pieces of MVC, which were also the main subject of this chapter: controllers and actions.

主站蜘蛛池模板: 三亚市| 营山县| 吴桥县| 搜索| 泰和县| 安塞县| 盱眙县| 青田县| 延津县| 应城市| 商洛市| 崇左市| 岳西县| 仙桃市| 荆门市| 依兰县| 收藏| 寿宁县| 朝阳市| 紫阳县| 乐陵市| 高淳县| 阿鲁科尔沁旗| 东明县| 阿拉善盟| 上杭县| 大埔区| 清新县| 平远县| 辽源市| 黄大仙区| 永春县| 黑龙江省| 炎陵县| 瓮安县| 仙游县| 正宁县| 拜泉县| 郸城县| 玉田县| 介休市|