惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
O
OpenAI News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
S
Security Affairs
SecWiki News
SecWiki News
Project Zero
Project Zero
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
P
Palo Alto Networks Blog
L
LINUX DO - 最新话题
H
Hacker News: Front Page
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
The GitHub Blog
The GitHub Blog
I
InfoQ
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
B
Blog
IT之家
IT之家
AWS News Blog
AWS News Blog
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
Security Latest
Security Latest
美团技术团队
C
Check Point Blog
WordPress大学
WordPress大学
T
Tenable Blog
S
Security @ Cisco Blogs
Last Week in AI
Last Week in AI
博客园 - 聂微东
月光博客
月光博客
博客园 - 【当耐特】
S
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
Schneier on Security
Schneier on Security
C
Cisco Blogs
Cyberwarzone
Cyberwarzone

博客园 - 大熊(BigBear)

ADO.net实现批量SQL操作. - 大熊(BigBear) - 博客园 Application_AcquireRequestState事件,导致Ajax客户端不能加载 CSLA.Net在Web项目中使用SQL2005的分页 Moss中Form验证中"找不到匹配项"问题的处理 对于知识库系统建设的思考 知识管理中知识地图详解〔转〕 知识管理中的一些概念 Aop面向方面编程之PostSharp框架 [摘]IIS上部署WCF的问题 Linq使用之分组 Silverlight表格绑定中的一点细节处理 - 大熊(BigBear) 页面加载性能的优化 由一棵树绑定引发的遐想 IBatis.Net使用MemCached替换内置缓存策略 .Net下调用Java安全Web服务 Webpart深入(二) Webpart深入(一) ASP.NET MVC 中文文档3 ASP.net MVC 中文文档1
ASP.NET MVC 中文文档2
大熊(BigBear) · 2008-11-01 · via 博客园 - 大熊(BigBear)

MVC Framework and Application 架构

介绍

ASP.NET Web site, URLs 映射到硬盘上的实际文件(通常 .aspx 文件). 这些 .aspx 文件包含顺序执行的代码以响应请求.

ASP.NET MVC framework 映射URLs 与之不同. 它映射URLscontroller. Controller 类处理请求, 用户的输入和交互, 以及执行恰当的程序和数据逻辑. (ASP.NET MVC controllers 实现的是前置控制模式.) 一个controller通常调用一个单独的视图来生成HTML输出.

ASP.NET MVC framework 分离model, view, controller组件. Model持久化数据到数据库来维持信息. Viewcontroller选择来渲染合适的UI. 默认的, ASP.NET MVC 使用已有的 ASP.NET (.aspx), master page (.master), user control (.ascx). controller定位到适当的action 方法, 获取values来作为action方法的参数, 并处理调用中发生的错误. 然后渲染了请求的view. 默认的每个组件都在 MVC Web application项目中独立的文件夹.

URL 映射

ASP.NET MVC 使用URL-routing 引擎提供弹性的URLs映射到controller. ASP.NET MVC中你可以定义路由规则处理URLs选择适当的controller. routing 引擎可自动的自动解析 URL中的变量, 并可将变量值传递到 controller作为参数.更多信息, see URL Routing with MVC.

MVC Framework and Postbacks

ASP.NET MVC不使用ASP.NET postback模式与后台交互. 而是将所有的终端用户路由到controller. 这保持了UI logic business logic的独立和可测试性. 结果, ASP.NET view state and ASP.NET 页面生存周期的事件没有集成在基于MVC的视图中.

Creating an ASP.NET MVC Application

ASP.NET MVC包含一个Visual Studio项目模板帮你创建MVC项目. 这个模板有所需的 folders, item templates, configuration-file entries.

Note: ASP.NET MVC模板是基于 ASP.NET Web Application 模板.你需要选择New ProjectFile菜单而不是 New Web Site.

当你创建一个新的MVC, Visual Studio有一个选项可以让你同时创建连个项目. 第一个是Web 项目,另一个是测试项目.
你可以使用任何测试框架测试 ASP.NET MVC 程序. Visual Studio 专业版包含testing-project支持MSTest. 更多信息, MSTest.exe Command-Line Options MSDN网站.

Web Application MVC 项目架构

当你创建一个ASP.NET MVC项目, MVC组件按文件夹分离如下图:

文件夹如下:

App_Data. 存放数据的物理位置. ASP.NET Web sites 中的角色一样.

Content folder. 推荐存放脚本, 样式表, 图片等. 通常存放静态文件.

Controllers folder. 推荐放置controllers. MVC要求所有的controllers以单词"Controller"结尾, HomeController, LoginController, or ProductController.

Models folder. Models放置model. 包含定义的对象和与数据交互的逻辑. 典型的, model对象是个独立的库. 然而, 当你创建一个新项目, 你可能先放在这里然后移到独立的类库中.

Scripts folder. 放置脚本文件. 默认含ASP.NET AJAX foundationJQuery .

Views folder. 推荐放置 views. 可以用.aspx, .ascx, and .master 文件, 和其他相关的文件views. Views文件夹给每个controller一个子文件夹;文件夹一 controller名字的前缀来命名. 例如, 你有一个controller名字为 HomeController, Views文件夹名字就Home. 默认, ASP.NET MVC加载一个view, 它在 Views\controllerName 文件夹查找一个 .aspx文件. 默认还有一个Shared 文件夹, 不与任何controller相关. 这个Sharedviews使用,为多个controllers共享.比如, 你可以在其中放置模板页.

另外前面列出的文件中, 有个Global.asax文件来设置全局的URL路由, 另外也使用Web.config文件配置应用程序.

设置默认的全局的URL路由

路由在Global.asax.cs文件中的Application_Start中初始化方法. 下面是个典型的Global.asax文件包含一个默认的路由.

Code