.Net - MVC Foundation

- Route:
Route = URLPattern + IRouteHandler

UrlRoutingModule -> MvcRouteHandler(IRouteHanlder) -> MvcHandler(IHttpHandler) -> Controller -> Action

RouteCollection.GetVirtualPath(routeValueDictionary).VirtualPath

Model (available in View): represent the current model instance.

ViewData (available in Controller and View): Represents a container that is used to pass data between a controller and a view.

ViewBag (available in Controller and View): dynamic edition of ViewData

TempData (available in Controller and View): ASP.NET Session data, represents a set of data that persists only from one request to the next.

RouteData (available in Controller): Encapsulates route variables of the route.

$RouteUrl (available in ASP.NET View): Generate Url,
<%$RouteUrl:year=2007, locale=CA, PathName=%>

- Error handling:
Add [HandleError] attribute to controller or action, it will use [/Views/Shared/Error.cshtml] as default View to show the error.

- Validate input:
Add [ValidateInput(false)] to the methods that don’t want to do the validation (HTML input checking).

- HTTP method
Add attributes [HttpPost][HttpGet][HttpPut][HttpDelete] to the method.

-HTTPS required
Add [RequireHttps] to the method.

-Authentication required
Add [Authorize] to the method.

 

ASP.NET/MVC

ASP.NET 模型视图控制器 (MVC)

ASP.NET Routing