1

Download ngx-admin from https://github.com/akveo/ngx-admin

2

Create a new Web Application in vs2017 through file->new->project->Select .Net Core->Select ASP.NET Core Web Application and Next->Select Empty Template(Not Angular) and OK

Now you have a .net core app and a ngx-admin app in different folders. Presume:

ngx-admin in D:\test\ngx-admin

asp.net application solution in D:\test\WebApplication1 and there's a project named WebApplication1 in D:\test\WebApplication1\WebApplication1

3

Copy all contents in D:\test\ngx-admin into D:\test\WebApplication1\WebApplication1. Yes only the contents, not the entire folder.

Don't panic. Although looks quite a mess in the .net core project folder now, you'll soon get along with it because your other modules of the .net core application don't have to stay in the same folder.

4

Open Webapplication1.sln using vs2017. Open Startup.cs and modify Configure method as below:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {

      if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} app.Map("/admin", appNgxAdmin => {
appNgxAdmin.UseSpa(spa => {
spa.Options.SourcePath = "src";
if (env.IsDevelopment()) {
spa.UseAngularCliServer(npmScript: "start");
}
});
}); app.UseMvc();
}

Modify ConfigureServices method as below:

    public void ConfigureServices(IServiceCollection services) {
    services.AddMvc();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration => {
configuration.RootPath = "dist";
});
}

Now you'll see several errors. Install Microsoft.AspNetCore.SpaServices.Extensions package through nuget. Get rid of the rest errors by adding using Microsoft.AspNetCore.SpaServices.AngularCli;

5

Open package.json, modify these 2 lines:

    "start": "ng serve --base-href=/admin/ --serve-path=/",
"build": "ng build --base-href=/admin/ --serve-path=/",

Save and right click package.json -> Restore Packges

Now try to run in vs2017 using IIS Express. Should show a blank page and if you go /admin , ngx-admin should already be working.

But there's a problem with some sockjs issue if you look at chrome dev-tool. I don't know why but could be an issue with Angular-cli earlier version which uses webpack-dev-server below v3. If you know how to solve it much appreciated if you can let me know.

Another issue is sometimes the browser complains 500 server error. Kindly let me know if you have the remedy.

It's normally not satisfying you yet. To make the whole thing working the backend controllers or alternatives are needed.

6

Notice we have services.AddMvc() and app.UseMvc() in place already which enables using controllers.

Create a Controllers folder under WebApplication1 project. Create a HomeController.cs class within it, with the content below:

using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
[Route("api/[controller]")]
public class HomeController : Microsoft.AspNetCore.Mvc.Controller {
[HttpGet]
public IActionResult Get() {
return Ok("Hello WebApplication1!");
}
}
}

Now run the project and visit /api/home should show Hello WebApplication1! in the browser.

The very basic procedure is done. To work on both backend and frontend in a sigle IDE is the harmony.

For more info about how to setup MVC in Asp.Net Core, here's an official link to go: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup

The default Mvc setup only allows you to use controllers within the project. If you prefer putting your controllers in different modules and leave only the Spa app(s) here in the main project(the "host" app) Orchard Core provides utilities with full flexibility.

To use Orchard Core utilities, for the moment I'm writing this article, a myget.org source has to be configured to nuget in vs2017(by clicking the configure icon next to the package source selector): https://www.myget.org/F/orchardcore-preview/api/v3/index.json

For WebApplication1 project, install OrchardCore.Application.Mvc.Targets , OrchardCore.Module.Targets (edit: and OrchardCore.Mvc.Core) packages through myget. Don't forget to check "Including Pre-release" because the utilities are still in beta versions.

Modify Startup.cs -> Configure method:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {

      if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} app.Map("/admin", appNgxAdmin => {
appNgxAdmin.UseSpa(spa => {
spa.Options.SourcePath = "src";
if (env.IsDevelopment()) {
spa.UseAngularCliServer(npmScript: "start");
}
});
});
    //app.UseMvc();
app.UseModules(); edit: later version UseOrchardCore();
}

Yes only the last line changed. Modify ConfigureService method:

    public void ConfigureServices(IServiceCollection services) {
    // services.AddMvc();
services.AddModules(); edit: later version services.AddOrchardCore().AddMvc();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration => {
configuration.RootPath = "dist";
});
}

Just the first line is changed.

Now create a .NET Standard Class Library(.NET Standard) project named MyControllers under your WebApplication1 solution.

Install OrchardCore.Application.Mvc.Targets and OrchardCore.Module.Targets packages for this project.

Create a class named MyController.cs under MyControllers project with the content:

using Microsoft.AspNetCore.Mvc;

namespace MyControllers
{
[Route("api/[controller]")]
public class MyController : Microsoft.AspNetCore.Mvc.Controller {
[HttpGet]
public IActionResult Get() {
return Ok("Hello MyControllers!");
}
}
}

Add reference to MyControllers project in WebApplication1 project.

Run and visit /api/my you should see Hello MyControllers! in the browser.

That's it. Simple and neat. How to link ngx-admin with the api is out of scope here. Guess shouldn't be a big issue.

ngx-admin with Asp.net Core 2.0, possibly plus OrchardCore的更多相关文章

  1. asp.net core 2.0 web api基于JWT自定义策略授权

    JWT(json web token)是一种基于json的身份验证机制,流程如下: 通过登录,来获取Token,再在之后每次请求的Header中追加Authorization为Token的凭据,服务端 ...

  2. 从头编写 asp.net core 2.0 web api 基础框架 (3)

    第一部分:http://www.cnblogs.com/cgzl/p/7637250.html 第二部分:http://www.cnblogs.com/cgzl/p/7640077.html 之前我介 ...

  3. Ubuntu & Docker & Consul & Fabio & ASP.NET Core 2.0 微服务跨平台实践

    相关博文: Ubuntu 简单安装 Docker Mac OS.Ubuntu 安装及使用 Consul Consul 服务注册与服务发现 Fabio 安装和简单使用 阅读目录: Docker 运行 C ...

  4. 【转载】从头编写 asp.net core 2.0 web api 基础框架 (3)

    Github源码地址:https://github.com/solenovex/Building-asp.net-core-2-web-api-starter-template-from-scratc ...

  5. Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员、后台管理员同时登录

    1.登录的实现 登录功能实现起来有哪些常用的方式,大家首先想到的肯定是cookie或session或cookie+session,当然还有其他模式,今天主要探讨一下在Asp.net core 2.0下 ...

  6. Asp.Net Core 2.0 项目实战(11) 基于OnActionExecuting全局过滤器,页面操作权限过滤控制到按钮级

    1.权限管理 权限管理的基本定义:百度百科. 基于<Asp.Net Core 2.0 项目实战(10) 基于cookie登录授权认证并实现前台会员.后台管理员同时登录>我们做过了登录认证, ...

  7. Docker & Consul & Fabio & ASP.NET Core 2.0 微服务跨平台实践

    相关博文: Ubuntu 简单安装 Docker Mac OS.Ubuntu 安装及使用 Consul Consul 服务注册与服务发现 Fabio 安装和简单使用 阅读目录: Docker 运行 C ...

  8. Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了

    Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了 Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Ne ...

  9. [Asp.net core 2.0]Ueditor 图片上传

    摘要 在项目中要用到富文本编辑器,包含上传图片,插入视频等功能.但ueditor只有.net版本,没有支持core.那么上传等接口就需要自己实现了. 一个例子 首先去百度ueditor官网下载简化版的 ...

随机推荐

  1. JS this用法详解

        随着对js的深入学习和使用,你会发现它里面包含了很多令人困惑的机制,比如对象.闭包.原型链继承等等 1.this是啥? 简言之,this是JavaScript语言中定义的众多关键字之一,它的特 ...

  2. UWB DWM1000 智能跟踪小车 --[蓝点无限]

    蓝点DWM1000 模块已经打样测试完毕,有兴趣的可以申请购买了,更多信息参见 蓝点论坛 UWB 智能跟踪小车:一共三个UWB模块,手持一个,小车上两个. 通过测量小车上两个模块与手持模块之间的距离, ...

  3. mac 配置 ssh 到git (Could not resolve hostname github.com, Failed to connect to github.com port 443 Operation timed out)

    1.进入终端命令行 (1)输入:cd .ssh/ 进入到.ssh后,输入ls,会输出“known_hosts”,如果没有创建过rsa的话 (2)输入:man ssh-add (3)输入:ssh-key ...

  4. Golang 微框架 Gin 简介

    框架一直是敏捷开发中的利器,能让开发者很快的上手并做出应用,甚至有的时候,脱离了框架,一些开发者都不会写程序了.成长总不会一蹴而就,从写出程序获取成就感,再到精通框架,快速构造应用,当这些方面都得心应 ...

  5. 4、json-server的使用

    json-server 详解 转载于https://www.cnblogs.com/fly_dragon/p/9150732.html JSON-Server 是一个 Node 模块,运行 Expre ...

  6. bulid tools

    输入:工程文件+编译说明文件: 处理:自动化构建工具+编译器: 输出:可执行文件. 相对于手动编译. 概述历史上 , 并通过构建自动化Makefile.今天 , 有两种一般类型的工具 : 自动工具 ( ...

  7. Nginx 自定义404、500、502 页面

    利用nginx的反向代理来实现 服务器404 和500 等状态码的自定义页面 1.nginx配置文件 nginx.conf 配置开启代理错误拦截 和配置页面  下划线部分  http { ...... ...

  8. 触发器中的after与before理解

    做一个表的insert的trigger,目的是只修改插入行的字段. CREATE OR REPLACE TRIGGER TR_RME_SLOT BEFORE INSERT ON RME_SLOT FO ...

  9. OO第一单元总结

    OO第一单元作业总结 一.前言 开学四周,不知不觉已经做了三次OO作业.事实上,每一次作业对我来说都是很大的挑战,需要花费大量的时间和精力来学习. 虽然学得很艰苦,但最后还是连滚带爬地完成了.(好惨一 ...

  10. EF Core 小坑:DbContextPool 会引起数据库连接池连接耗尽

    DbContextPool 是 ASP.NET Core 2.1 引入的新特性,可以节省创建 DbContext 实例的开销,但没有想到其中藏着一个小坑. 最近有一个 ASP.NET Core 项目持 ...