From 7c367969bc8b83b302c1c7216880164ed50c2eed Mon Sep 17 00:00:00 2001 From: heyixiaoran Date: Sat, 25 Jun 2016 23:50:07 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet/tutorials/first-mvc-app/details.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aspnet/tutorials/first-mvc-app/details.rst b/aspnet/tutorials/first-mvc-app/details.rst index 4d18d74e4..3f474abbe 100644 --- a/aspnet/tutorials/first-mvc-app/details.rst +++ b/aspnet/tutorials/first-mvc-app/details.rst @@ -25,9 +25,9 @@ :dedent: 8 :emphasize-lines: 5 -代码先行(Code First)模式使用 SingleOrDefaultAsync 方法更易于数据搜索。这个方法包含的一个重要安全功能,就是在代码尝试用电影记录在做任何操作之前确保查找方法已经找到了一条电影记录。例如,黑客可以把链接产生的 URL 从 *http://localhost:xxxx/Movies/Details/1* 改成类似于 *http://localhost:xxxx/Movies/Details/12345* (或者其他非实际电影记录的值),从而给网站带来错误。如果您不检查影片是否为空,应用程序将会抛出异常。 +代码先行(Code First)模式使用 SingleOrDefaultAsync 方法更易于数据搜索。这个方法包含的一个重要的安全功能,就是在代码尝试用电影记录做任何操作之前确保查找方法已经找到了一条电影记录。例如,黑客可以把产生的链接 URL 从 *http://localhost:xxxx/Movies/Details/1* 改成类似于 *http://localhost:xxxx/Movies/Details/12345* (或者其他非实际电影记录的值),从而给网站带来错误。如果你不检查影片是否为空,应用程序将会抛出异常。 -查看 Delete 方法和 DeleteConfirmed 的方法 +查看 Delete 方法和 DeleteConfirmed 方法 .. literalinclude:: start-mvc/sample/src/MvcMovie/Controllers/MoviesController.cs :language: c# @@ -36,18 +36,18 @@ 需要注意的是 ``HTTP GET Delete`` 方法不删除指定的影片,它返回一个你可以提交 (HttpPost) 删除操作的 Movie 的视图。如果在对 GET 请求的响应中执行删除操作(或者编辑,创建,或任何其他更改数据的操作)将会引入一个安全漏洞。 -真正删除数据的 ``[HttpPost]`` 方法被命名为 ``DeleteConfirmed`` ,使这个 HTTP POST 方法有了唯一的签名或名称。这两个方法的签名如下: +真正删除数据的 ``[HttpPost]`` 方法被命名为 ``DeleteConfirmed`` ,给这个 HTTP POST 方法一个唯一的签名或名称。这两个方法的签名如下: .. literalinclude:: start-mvc/sample/src/MvcMovie/Controllers/MoviesController.cs :language: c# :lines: 119-120,135-136,139 :dedent: 8 -公共语言运行时(CLR)需要重载方法有一个唯一的参数签名(相同的方法名,但不同的参数列表)。然而,在这里你需要两个 ``Delete`` 方法 – 一个 GET 请求一个 POST 请求 – 并且它们都具有相同的参数签名。(它们都接受一个整数作为参数)。 +公共语言运行时(CLR)要求重载方法有一个唯一的参数签名(相同的方法名,但不同的参数列表)。然而,在这里你需要两个 ``Delete`` 方法 – 一个 GET 请求一个 POST 请求 – 并且它们都具有相同的参数签名。(它们都需要接收一个整数作为参数)。 -有两种方案可以解决该问题,其中一种方法是,赋予方法不同的名称。这就是基架机制在前面的例子所做的事情。然而,这引入了一个小问题: ASP.NET 利用名字将 URL 段映射到 action 方法,如果你重命名一个方法,路由通常将无法找到该方法。解决的办法就是你在例子中看到的,就是为 ``DeleteConfirmed`` 方法添加 ``ActionName("Delete")`` 特性。该特性为路由系统执行映射,所以一个 POST 请求的包含 /Delete/ 的 URL 会找到 ``DeleteConfirmed`` 的方法。 +有两种方案可以解决该问题,其中一种方法是,赋予方法不同的名称。这就是基架机制在前面的例子所做的事情。但是,这个方法引入了一个小问题: ASP.NET 利用名字将 URL 段映射到 action 方法,如果你重命名一个方法,路由通常将无法找到该方法。解决的办法就是你在例子中看到的,就是为 ``DeleteConfirmed`` 方法添加 ``ActionName("Delete")`` 特性。该特性为路由系统执行映射,所以一个 POST 请求的包含 /Delete/ 的 URL 会找到 ``DeleteConfirmed`` 的方法。 -对于具有相同名称和参数签名的方法,另一种常见的的解决办法,是通过人为的改变 POST 方法的签名,即包含一个附加的(未使用)参数。这就是我们在前面文章中已经添加的 ``unused`` 的参数。在这里你可以对 ``[HttpPost] Delete`` 方法采用同样的解决办法: +对于具有相同名称和参数签名的方法,另一种常见的的解决办法是通过人为的改变 POST 方法的签名,即包含一个附加的(未使用)参数。这就是我们在前面文章中已经添加的 ``unused`` 的参数。在这里你可以对 ``[HttpPost] Delete`` 方法采用同样的解决办法: .. literalinclude:: start-mvc/sample/src/MvcMovie/Controllers/MoviesController.cs :language: c# From 5bee2f5be14dfe0f49bf92388e33bafaf497d155 Mon Sep 17 00:00:00 2001 From: heyixiaoran Date: Sun, 26 Jun 2016 00:06:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet/client-side/angular.rst | 219 +++++++++++++++++---------------- 1 file changed, 112 insertions(+), 107 deletions(-) diff --git a/aspnet/client-side/angular.rst b/aspnet/client-side/angular.rst index 48fb48f83..79c981b91 100644 --- a/aspnet/client-side/angular.rst +++ b/aspnet/client-side/angular.rst @@ -1,34 +1,36 @@ -Using Angular for Single Page Applications (SPAs) +使用Angular构建单页应用程序(SPAs) ================================================= -By `Venkata Koppaka`_ and `Scott Addie`_ +作者: `Venkata Koppaka`_ 和 `Scott Addie`_ -In this article, you will learn how to build a SPA-style ASP.NET application using AngularJS. +翻译: `耿晓亮(Blue)`_ + +在本文中你会学到如何通过 AngularJS 构建一个 SPA-style ASP.NET 应用程序。 .. contents:: Sections: :local: :depth: 1 -`View or download sample code `__ +`查看或者下载示例代码 `__ -What is AngularJS? +什么事 AngularJS? ------------------ -`AngularJS `_ is a modern JavaScript framework from Google commonly used to work with Single Page Applications (SPAs). AngularJS is open sourced under MIT license, and the development progress of AngularJS can be followed on `its GitHub repository `_. The library is called Angular because HTML uses angular-shaped brackets. +`AngularJS `_ 是 Google 通常用来处理单页面应用程序(SPAs)的一个现代化 JavaScript 框架。AngularJS 是遵从 MIT 协议的开源项目,AngularJS 的开发进度可以跟踪 `它的 GitHub repository `_。因为 HTML 使用尖角号所以命名 Angular。 -AngularJS is not a DOM manipulation library like jQuery, but it uses a subset of jQuery called jQLite. AngularJS is primarily based on declarative HTML attributes that you can add to your HTML tags. You can try AngularJS in your browser using the `Code School website `_. +AngularJS 不是像 jQuery 一样的 DOM 操作库,但是它用了 jQuery 的一个叫 jQLite 的子集。AngularJS 主要是基于 HTML 特性的声明所有你可以添加到 HTML 标签里。你可以通过 `Code School 网站 `_ 在浏览器里尝试 AngularJS。 -Version 1.5.x is the current stable version and the Angular team is working towards a big rewrite of AngularJS for V2.0 which is currently still in development. This article focuses on Angular 1.X with some notes on where Angular is heading with 2.0. +当前稳定版是 1.5.x 并且 Angular 团队正在致力于 AngularJS 的一个大改动的 V2.0 版目前仍然在开发中。本文专注在 Angular 1.X 附带一些 Angular 2.0 方向的注释。 -Getting Started +入门 --------------- -To start using AngularJS in your ASP.NET application, you must either install it as part of your project, or reference it from a content delivery network (CDN). +开始在 ASP.NET 应用程序里应用 AngularJS 前,首先你必须安装它来作为你项目的一部分,或者从内容分发网络(CDN)引用。 -Installation +安装 ^^^^^^^^^^^^ -There are several ways to add AngularJS to your application. If you’re starting a new ASP.NET Core web application in Visual Studio, you can add AngularJS using the built-in :ref:`Bower ` support. Simply open ``bower.json``, and add an entry to the ``dependencies`` property: +有几种方式添加 AngularJS 到你的应用程序。如果你正在 Visual Studio 里开始一个新的 ASP.NET Core web 应用程序,你可以通过内置 :ref:`Bower ` 添加 AngularJS 。只需打开 ``bower.json``,并添加一个条目到 ``dependencies`` 属性: .. _angular-bower-json: @@ -37,12 +39,12 @@ There are several ways to add AngularJS to your application. If you’re startin :linenos: :emphasize-lines: 9 -Upon saving the ``bower.json`` file, Angular will be installed in your project's ``wwwroot/lib`` folder. Additionally, it will be listed within the ``Dependencies/Bower`` folder. See the screenshot below. +一旦保存 ``bower.json`` 文件,Angular 将会安装到项目的 ``wwwroot/lib`` 文件夹。另外,还会在 ``Dependencies/Bower`` 文件夹中列出来。见下边的截图。 .. image:: angular/_static/angular-solution-explorer.png :width: 283px -Next, add a ``