前言

本文是翻译文章,如有翻译不正确的地方请指正。
其中内容大部分是官方原文,加上自己根据操作实现的心得。
官方 原文https://aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template-Angular#source-code

简介(Introduction)

The easiest way of starting a new project using ABP with ASP.NET Core with Angular is to create a template on templates page. Remember to check “Include module zero”. After creating and downloading your project, follow below steps to run your application.

开始一个新使用Angular和 ASP.NET Core 的ABP项目最简单的方法就是通过官方的模板页面来生成模板。切记包含zero模块。在官网完成创建和下载你的项目后,跟随后面的步骤来运行你的应用。

下载地址:https://aspnetboilerplate.com/Templates

ASP.NET Core项目介绍(ASP.NET Core Application)

  • Open your solution on Visual Studio 2017+ and build the solution.
  • Select the ‘Web.Host’ project as startup project.
  • Open Package Manager Console and run Update-Database command to create your database (ensure that Default project is selected as .EntityFrameworkCore in the Package Manager Console window).
  • Run the application. It will show swagger-ui if it is successfull:
  • 用vs2017及其以上版本打开解决方案,然后生成解决方案
  • 选择 ‘Web.Host’ 为启动项目。
  • 打开程序包管理控制台,然后输入Update-Database 指令来创建你的数据库(确保程序包管理控制台中的默认项目选择的是‘EntityFrameworkCore’)。
  • 运行程序,如果成功将会显示 swagger-ui。

这里还有一点我要补充一下就是数据库连接需要根据实际情况进行修改,在‘Web.Host’工程项目下面的appsetting.json中。和以往的mvc项目不同。
下面是我按照上面方法启动后的效果:

In this template, multi-tenancy is enabled by default. You can disable it in Core project’s module class if you don’t need.

在这个模版中,multi-tenancy默认是启用的,如果需要,你可以在core项目中禁用他们

If you have problems with running the application, please try close and open your Visual Studio again. It sometimes fail on first package restore.

如果在运行过程中出现什么问题,请尝试关闭你的vs然后重新打开。往往在第一次还原包的时候容易失败。

Angular项目 (Angular Application)

Angular application needs to following tools be installed:
- nodejs 6.9+ with npm 3.10+
- Typescript 2.0+
We used angular-cli to develop the Angular application.

Angular 项目需要按照下面的工具:
- nodejs 6.9版本及其以上,npm3.10版本及其以上
- Typescript 2.0版本及其以上
我们是用angular-cli来构建的Angular项目。

Restore Packages
Open a command prompt, navigate to angular folder which contains *.sln file and run the following command to restore npm packages:

还原包

打开命令提示符,并进入angular的文件夹,执行下面命令还原npm包。

npm install

Notice that npm install may show some warn messages, which is not related to our solution and generally it’s not a problem. The solution can also configured to work with yarn and we suggest to use it if available on your computer.

注意,npm安装包时可能会出现一些警告信息,这不是我们的解决方案相关的一般没问题。该解决方案还可以配置在yarn上运行,如果你的电脑可以使用yarn,我们建议使用。

Run The Application
In your opened command prompt, run the following command:

运行程序

在你的命令提示符中执行下面命令:

npm start

Once the application compiled, you can browse http://localhost:4200 in your browser. Be sure that Web.Host application is running at the same time. When you open the application, you will see the login page:

项目一旦编译完成,你可以在浏览器中输入http://localhost:4200 ,前提要确定与此同时你的.net项目中 Web.Host 工程正在运行。当你打开项目,你可以看见登录页面。

就翻译到这里把,因为npm编译出现错误,一时半会也解决不了。

早就听说java编程对版本的要求很严格,node这套开发显然和java开发很类似,对于我们新手总数莫名奇妙因为引用版本不同而导致错误。

于是我确保了下node版本,npm版本符合要求的情况下,重新安装了typescript,再执行npm install,npm start ,出乎意料的编译成功了。

Angular client app has also HMR (Hot Module Replacement) enabled. You can use the following command (instead of npm start) to enable HMR on development time:
Angular 客户端程序同样支持HMR (Hot Module Replacement),在开发的时候,你可以用下面的指令来启动HMR

npm run hmr

对于node开发项目有点了解的人都知道,有package.json这么一个文件,里面包含了一些信息,就包括上面这些指令,还有依赖的包及其版本

Login
Now you can login the application using default credentials. User name is ‘admin’ and password is ‘123qwe’ as default. If you want to login as a tenant, first switch to that tenant in login page. There is a tenant named “Default” by default. Once you login successfully, you will see a dashboard:

登陆

现在你可以用默认的证书登录应用。默认用户名是admin,密码是123qwe,如果你想作为一个租户登录,首先在登陆页面切换租户,这里提供一个名字叫做”Default”的默认租户,一旦你登陆成功,你会看见这样一个面板。

很明显我的样式出现了问题,后面再解决。继续翻译。

正常的应该是这样的

This dashboard is just for demonstration and to be a base for your actual dashboard.

这个面板只是一个demo,它只是你实际面板的基础。

Deployment of Angular Application
We used angular-cli tooling to build Angular solution. You can use ng build command to publish your project. It publishes to dist folder by default. Then you can host this folder on IIS or any web server you like.

部署Angular项目

我们用 angular-cli 工具来生成Angular解决方案,你可以用ng build 指令来发布你的工程项目,发布内容默认放在dist文件夹下,然后你可以将这个文件夹部署到iis或者其他你喜欢的web服务器下面。

解决方案明细及其他特性( Solution Details & Other Features)

Token Based Authentication
If you want to consume APIs/application services from a mobile application, you can use token based authentication mechanism just like we do it for Angular client. Startup template includes JwtBearer token authentication infrastructure.

基于令牌的认证

如果您想从移动应用程序中使用API /应用程序服务,您可以使用基于令牌的认证机制,就像我们为Angular 客户端那样做。启动模板包括jwtbearer令牌认证基础设施。

Here, Postman (chrome extension) will be used to demonstrate requests and responses.

这里,我们用Postman(Chrome的扩展)来演示请求和响应。

Authentication
Just send a POST request to http://localhost:21021/api/TokenAuth/Authenticate with Context-Type=”application/json” header as shown below:

认证

只需要向http://localhost:21021/api/TokenAuth/Authenticate发送一个头包含 Context-Type=”application/json”的post请求,如下所示

We sent values usernameOrEmailAddress and password. As seen above, result property of returning JSON contains the token and expire time (which is 24 hours by default and can be configured). We can save it and use for next requests.

如上所示我们发送用户名和密码的值,结果返回JSON数据包含令牌和过期时间(默认是24小时,可以配置)。我们可以保存它并用于下一个请求。

About Multi Tenancy
API will work as host users by default. You can send Abp.TenantId header value to work with a specified tenant. It’s an integer value and 1 for default tenant by default.

关于多租户

默认情况下,api将作为主机用户工作。你可以把abp.tenantid头的值指定一个特殊租户。默认情况下,默认的租户是一个整型值1。

Use API
After authenticate and get the token, we can use it to call any authorized action. All application services are available to be used remotely. For example, we can use the User service to get a list of users:

用户api

经过验证后得到令牌,我们可以用它来调用任何授权的方法。所有的应用服务可以远程使用。例如,我们可以使用用户服务获得用户列表:

Just made a GET request to http://localhost:21021/api/services/app/user/getAll with Content-Type=”application/json” and Authorization=”Bearer your-auth-token “. All functionality available on UI is also available as API.

我们只需要向http://localhost:21021/api/services/app/user/getAll 发送一个get请求,包含Content-Type=”application/json”和Authorization=”Bearer your-auth-token “UI上可用的所有功能API也可以实现。

Migrator Console Application
Startup template includes a tool, Migrator.exe, to easily migrate your databases. You can run this application to create/migrate host and tenant databases.

控制台数据迁移

启动模板包括一个工具,migrator.exe,可以轻松迁移您的数据库。您可以运行此应用程序来创建/迁移主机和租户数据库。

This application gets host connection string from it’s own appsettings.json file. It will be same in the appsettings.json in the .Web.Host project at the beggining. Be sure that the connection string in config file is the database you want. After getting host connection sring, it first creates the host database or apply migrations if it does already exists. Then it gets connection strings of tenant databases and runs migrations for those databases. It skips a tenant if it has not a dedicated database or it’s database is already migrated for another tenant (for shared databases between multiple tenants).

这个应用程序从主机的appsettings.json文件中获取连接字符串。开始它和Web.Host中的appsettings.json文件一样。确保在配置文件中的连接字符串是要数据库。获取主机的连接字符串后,它首先创建主数据库或应用的迁移,如果它已经存在。然后它就会获取租户数据库连接字符串和运行的数据库迁移。如果没有专用数据库,或者它的数据库已经迁移到另一个租户(用于多个租户之间的共享数据库),它就会跳过该租户。

You can use this tool on development or on product environment to migrate databases on deployment, instead of EntityFramework’s own tooling (which requires some configuration and can work for single database/tenant in one run).

你可以在开发或生成环境迁使用这个工具来迁移数据,而不是使用EntityFramework自己的工具(这需要一些配置,而且可以在一个单个数据库/租户的工作)。

Unit Testing
Startup template includes test infrastructure setup and a few tests under the .Test project. You can check them and write similar tests easily. Actually, they are integration tests rather than unit tests since they tests your code with all ASP.NET Boilerplate infrastructure (including validation, authorization, unit of work…).

单元测试

启动模板包括测试基础设施和一些测试例子在测试项目下。你可以查看,并且很轻松的写类似的测试。实际上,他们因为测试你的代码与所有的ASP.NET样板的基础设施,所以算是集成测试而不是单元测试(包括验证、授权、工作单位…)。

Source Code

This project template is developed as open source and free under Github: https://github.com/aspnetboilerplate/module-zero-core-template

源码

这个项目模板的作为开源免费项目,项目地址在
Github:https://github.com/aspnetboilerplate/module-zero-core-template

样式问题解决办法(一看就是因为样式缺失导致的)

在index.html中加入下面标签

<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

开始使用ABP.CORE模板 (ASP.NET Core with Angular)相关推荐

  1. 微软BUG Bounty悬赏项目扩展至.NET Core和ASP.NET Core

    微软宣布自 2016 年 9 月 1 日开始将 .NET Core 和 ASP.NET 纳入到 BUG Bounty 悬赏项目范围内,微软将会为 Windows 和 Linux 平台上的两个编程代码提 ...

  2. java和asp.net core_.NET Core和ASP.NET Core简介与区别

    1..NET Core简介 .NET Core是适用于 windows.linux 和 macos 操作系统的免费.开源托管的计算机软件框架,是微软开发的第一个官方版本,具有跨平台 (Windows. ...

  3. .NET Core amp; ASP.NET Core 1.0在Redhat峰会上正式发布

    众所周知,Red Hat和微软正在努力使.NET Core成为Red Hat企业版Linux (RHEL)系统上的一流开发平台选项.这个团队已经一起工作好几个月了,RHEL对.NET有许多需求.今天在 ...

  4. ASP.NET Core 用户注册 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 用户注册 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 用户注册 上一章节我们终于迁移完了 Identity 的数据,也创建 ...

  5. .NET Core和ASP.NET Core简介与区别

    本文主要简单介绍一下.NET Core和ASP.NET Core,以及它们之前的联系和区别. 原文地址:.NET Core和ASP.NET Core简介与区别

  6. 【ASP.NET Core】ASP.NET Core 依赖注入

    一.什么是依赖注入(Denpendency Injection) 这也是个老身常谈的问题,到底依赖注入是什么? 为什么要用它? 初学者特别容易对控制反转IOC(Iversion of Control) ...

  7. core+2.0+mysql_【Asp.Net Core】ASP.NET Core 2.0 + EF6 + Linux +MySql混搭

    好消息!特好消息!同时使用ASP.NET Core 2.0和.NET Framework类库还能运行在linux上的方法来啦! 是的,你没有看错!ASP.NET Core 2.0,.NET Frame ...

  8. Azure 上使用 Windows Server Core 运行 ASP.NET Core 网站

    点击上方蓝字关注"汪宇杰博客" 导语 微软智慧云 Azure 上虽然早就有 App Service 这种完全托管的 PaaS 服务可以让我们分分钟建网站.但是不自己配一下环境,就不 ...

  9. EF Core与ASP.NET Core 的集成

    目录 一.分层项目中EF Core的用法 二.使用"上下文池"时要谨慎 三.案例:批量注册上下文 一.分层项目中EF Core的用法 在编写简单的演示案例的时候,我们通常会把项目的 ...

最新文章

  1. 前、后端分离权限控制设计和实现思路
  2. 我玩《王者荣耀》、斗地主、打麻将,但我是正经搞AI的北大教授
  3. Appium+RobotFrameWork测试环境搭建
  4. 无权无向和加权网络的聚类系数
  5. java文件读取的总结_java 读取文件方法的总结
  6. Intel Hyperscan简介
  7. vasp软件全名是什么_qvasp一款简单易用的VASP辅助计算软件
  8. 边缘计算,又一个轮回
  9. stm32电容触摸按键实验
  10. ios 强制横屏大总结
  11. no.4京东话费充值系统架构演讲读后感
  12. 在服务器上设置虚拟传入,如何配置 SMTP 虚拟服务器以进行邮件传递
  13. java访问excel表格_Java读取excel表格(示例代码)
  14. Matlab R2012b 重复激活,License 失效问题解决
  15. 算法工程师,上岸了!
  16. onlyoffice转换html,CentOS7安装onlyoffice实现word的在线预览和编辑
  17. 浙江省计算机提前招分数线,【高考】2020年浙江省提前批各高校录取分数线汇总,建议收藏...
  18. locust之执行方式
  19. 初中数学与计算机论文,初中数学优秀论文15篇
  20. 拥有资源的多少并不重要,如果不懂得利用,永远是不够的

热门文章

  1. 在调试器里看LINUX内核态栈溢出
  2. 音视频相关研究-英年早逝的雷宵骅在读博士的项目
  3. 【嵌入式】嵌入式开发为什么要跑操作系统?
  4. SEM计算机价格计算,百度竞价SEMWHY:排名机制、价格计算公式是什么?
  5. macOS 中 Cornerstone 的Clean操作和终端的svn cleanup命令无效了怎么办?
  6. 用Python做兼职是如何挣钱的?
  7. CSS精灵技术与字体图标
  8. 皮尔松相关分析_皮尔西斯符号学与生物学认知
  9. ElasticSearch那些事儿(五)
  10. GOOGLE搜索秘籍