The blog record any valuable point from the free book. 《Professional ASP.NET MVC 1.0》!

The blog write by volnet.

1.Page 12/196

ASP.NET MVC projects by default have six top-level directories:

Directory Purpose
/Controllers Where you put Controller classes that handle URL requests
/Models Where you put classes that represent and manipulate data
/Views Where you put UI template files that are responsible for rendering output
/Scripts Where you put JavaScript library files and scripts (.js)
/Content Where you put CSS and image files, and other non-dynamic/non-JavaScript content
/App_Data Where you store data files you want to read/write.

ASP.NET MVC does not require this structure. In fact, developers working on large applications will
typically partition the application up across multiple projects to make it more manageable (for example:
data model classes often go in a separate class library project from the web application). The default
project structure, however, does provide a nice default directory convention that we can use to keep
our application concerns clean.

2.Page 28/196

In a model-view-controller framework the term “model” refers to the objects that represent the data of
the application, as well as the corresponding domain logic that integrates validation and business rules
with it.
The model is in many ways the “heart” of an MVC-based application, and as we’ll see later fundamentally drives the behavior of it.

3.Page 31/196

By default the LINQ to SQL designer automatically "pluralizes" table and column names when it creates
classes based on a database schema. For example: the "Dinners" table in our example above resulted in
a "Dinner" class. …

By default the LINQ to SQL designer also inspects the primary key/foreign key relationships of the tables,
and based on them automatically creates default "relationship associations" between the different
model classes it creates. For example, …

4.Page 42/196

We can use .NET’s regular expression support to implement this phone validation support. Below is a
simple PhoneValidator implementation that we can add to our project that enables us to add countryspecific
Regex pattern checks:

Click here to get code!

All these code is the same as before. (Click here to collapse!)

public class PhoneValidator {
static IDictionary<string, Regex> countryRegex =
    new Dictionary<string, Regex>() {
        { "USA", new Regex("^[2-9]\\d{2}-\\d{3}-\\d{4}$")},
        { "UK", new
            Regex("(^1300\\d{6}$)|(^1800|1900|1902\\d{6}$)|(^0[2|3|7|8]{1}[0-
                9]{8}$)|(^13\\d{4}$)|(^04\\d{2,3}\\d{6}$)")},
                { "Netherlands", new Regex("(^\\+[0-9]{2}|^\\+[0-
                9]{2}\\(0\\)|^\\(\\+[0-9]{2}\\)\\(0\\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\\-
                \\s]{10}$)")},
    };
    public static bool IsValidNumber(string phoneNumber, string country) {
        if (country != null && countryRegex.ContainsKey(country))
            return countryRegex[country].IsMatch(phoneNumber);
        else
            return false;
    }
    public static IEnumerable<string> Countries {
        get {
            return countryRegex.Keys;
        }
    }
}

5.Page 43/196

Because our validation and business rules are implemented within our domain model layer, and not
within the UI layer, they will be applied and used across all scenarios within our application. We can
later change or add business rules and have all code that works with our Dinner objects honor them.
Having the flexibility to change business rules in one place, without having these changes ripple
throughout the application and UI logic, is a sign of a well-written application, and a benefit that an MVC
framework helps encourage.

6.Page 44/196

Web-based MVC frameworks map URLs to server code in a slightly different way. Instead of mapping
incoming URLs to files, they instead map URLs to methods on classes. These classes are called
“Controllers” and they are responsible for processing incoming HTTP requests, handling user input,
retrieving and saving data, and determining the response to send back to the client (display HTML,
download a file, redirect to a different URL, etc).

7.Page 50/196

Separating our controller logic from our view rendering brings several big benefits. In particular it helpsenforce a clear "separation of concerns" between the application code and UI formatting/rendering code. This makes it much easier to unit-test application logic in isolation from UI rendering logic. It makes it easier to later modify the UI rendering templates without having to make application code changes. And it can make it easier for developers and designers to collaborate together on projects.

8.Page 77/196

You might ask – why are we using a single URL and differentiating its behavior via the HTTP verb? Why not just have two separate URLs to handle loading and saving edit changes? For example:
/Dinners/Edit/[id] to display the initial form and /Dinners/Save/[id] to handle the form post to save it?
The downside with publishing two separate URLs is that in cases where we post to /Dinners/Save/2, and then need to redisplay the HTML form because of an input error, the end-user will end up having the /Dinners/Save/2 URL in their browser’s address bar (since that was the URL the form posted to). If the end-user bookmarks this redisplayed page to their browser favorites list, or copy/pastes the URL and emails it to a friend, they will end up saving a URL that won’t work in the future (since that URL depends on post values).
By exposing a single URL (like: /Dinners/Edit/[id]) and differentiating the processing of it by HTTP verb, it is safe for end-users to bookmark the edit page and/or send the URL to others.

9.Page 96/196

You might ask – why did we go through the effort of creating a <form> within our Delete confirmation screen? Why not just use a standard hyperlink to link to an action method that does the actual delete operation?
The reason is because we want to be careful to guard against web-crawlers and search engines discovering our URLs and inadvertently causing data to be deleted when they follow the links. HTTPGET based URLs are considered “safe” for them to access/crawl, and they are supposed to not follow HTTP-POST ones.
A good rule is to make sure you always put destructive or data modifying operations behind HTTP-POST requests.

10.Page 129/196

For Internet web applications, the most common authentication approach used is called “Forms Authentication”. Forms Authentication enables a developer to author an HTML login form within their application, and then validate the username/password an end-user submits against a database or other password credential store. If the username/password combination is correct, the developer can then ask ASP.NET to issue an encrypted HTTP cookie to identify the user across future requests.

另外刚刚发现还有个中文版的链接:http://bit.ly/uyAtI

ASP.NET MVC – Nerdinner - notes相关推荐

  1. 我要学ASP.NET MVC 3.0(一): MVC 3.0 的新特性

    摘要 MVC经过其1.0和2.0版本的发展,现在已经到了3.0的领军时代,随着技术的不断改进,MVC也越来越成熟.使开发也变得简洁人性化艺术化. 园子里有很多大鸟都对MVC了如指掌,面对问题犹同孙悟空 ...

  2. ASP.NET MVC使用Bootstrap系统(2)——使用Bootstrap CSS和HTML元素

    ASP.NET MVC使用Bootstrap系统(2)--使用Bootstrap CSS和HTML元素 阅读目录 Bootstrap 栅格(Grid)系统 Bootstrap HTML元素 Boots ...

  3. asp.net mvc 页面传值的方法总结

    转自:http://msprogrammer.serviciipeweb.ro/2012/01/15/usual-methods-to-transfer-data-from-page-to-page- ...

  4. ASP.NET MVC使用Bootstrap系列(3)——使用Bootstrap 组件

    Bootstrap为我们提供了十几种的可复用组件,包括字体图标.下拉菜单.导航.警告框.弹出框.输入框组等.在你的Web Application中使用这些组件,将为用户提供一致和简单易用的用户体验. ...

  5. [转] Asp.net mvc 3 beta 新特性介绍

    Links:http://www.cnblogs.com/n-pei/archive/2010/10/11/1848089.html 国庆放假归来,刚好赶上asp.net mvc 3 beta发布,和 ...

  6. ASP.NET MVC 3.0(一): MVC 3.0 的新特性 摘要

    ASP.NET MVC 3.0(一): MVC 3.0 的新特性 摘要 ASP.NET MVC 3.0(二): MVC的概念及MVC 3.0开发环境 ASP.NET MVC 3.0(三): 初识MVC ...

  7. ASP.NET MVC预览4-使用Ajax和Ajax.Form

    ASP.NET MVC Preview 4 is up on CodePlex. The Gu has all the exquisite Gu-Like Detail on his blog. Ph ...

  8. ASP.NET MVC 2示例Tailspin Travel

    Tailspin Travel 是一个旅游预订的应用程序示例,最新版本采用ASP.NET MVC 2技术构建,主要使用 DataAnnotations 验证, 客户端验证和ViewModels,还展示 ...

  9. Asp.net MVC中的ViewData与ViewBag

    在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...

最新文章

  1. 由Node.js事件驱动模型引发的思考
  2. 裴健:搜索皆智能,智能皆搜索
  3. Tivoli NetView
  4. [解决]CXF wsdl2java 生成代码存在的一些问题
  5. c# 串口最简单接收十六进制
  6. python入门程序异常_Python入门基础(10)_异常_1
  7. ubuntu 下telnet 操纵memcache 实现
  8. ui设计师常用的设计工具_2020年应该使用哪个UI设计工具?
  9. ASP.NET MVC 使用Log4Net记录系统运行中问题
  10. 光纤交换机zone配置
  11. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could
  12. 搭建Open××× Server路由模式、证书认证
  13. python setup.py_python setup.py 构建
  14. SQL Sever的安装教程
  15. Android源码提取系统签名
  16. 【计网CRC】模2除法求冗余码
  17. ps怎么撤销参考线_Photoshop120条新手必备技巧
  18. mysql workbench6.3.5_mysql workbench
  19. 古训:能控制早晨的人,方可控制人生(经典)
  20. linux平台使用yum安装mysql

热门文章

  1. Linux jobs等前后台运行命令详解
  2. socket的阻塞非阻塞方法在缓冲区的差别
  3. sae上部署第一个站
  4. Linux Kernel TCP/IP Stack — L3 Layer — 路由器子系统
  5. 边缘计算 — MEC 与运营商
  6. C 语言编程 — 宏定义与预处理器指令
  7. Ceph 的用户管理与认证
  8. 机智云明星开发者 | 董程森
  9. mysql将字符串字段转为数字排序或比大小
  10. [C编码笔记] 空串与NULL是不一样的