1、更正popper.js的错误
2、打包js
3、添加服务与路由,中间件css
emmm,今天来更正些昨天的错误
那个package.json里面的popper改成"popper.js": “1.14.6”,后面的版本也改下,而后点击保存node
{ "version": "1.0.0", "name": "asp.net", "private": true, "devDependencies": { "bootstrap": "4.2.1", "jquery-slim": "3.0.0", "popper.js": "1.14.6" } }
在wwwroot/js文件夹下添加site.js
而后打开bundleconfig.json进行js打包操做jquery
[ { "outputFileName": "wwwroot/css/all.min.css", "inputFiles": [ "node_modules/bootstrap/dist/css/bootstrap.css", "wwwroot/css/site.css" ] }, //上面用于开发 //下面用于生产 { "outputFileName": "wwwroot/css/bootstrap.css", "inputFiles": [ "node_modules/bootstrap/dist/css/bootstrap.css" ], "minify": { "enabled": false //意为没有对它进行压缩 } }, //js { "outputFileName": "wwwroot/js/all.min.js", "inputFiles": [ "node_modules/jquery-slim/dist/jquery.slim.js", "node_modules/popper.js/dist/js/popper.js", "node_modules/bootstrap/dist/js/bootstrap.js", "wwwroot/js/site.js" ], "minify": { "enabled": true, "renameLocals": true //true重命名局部变量 }, "sourceMap": false //一个存储源代码与编译代码对应位置映射的信息文件 }, { "outputFileName": "wwwroot/js/vendor.js", "inputFiles": [ "node_modules/jquery-slim/dist/jquery.slim.js", "node_modules/popper.js/dist/js/popper.js", "node_modules/bootstrap/dist/js/bootstrap.js" ], "minify": { "enabled": false } } ]
而后点击解决方案,店家从新生成
js文件夹就会多出两个web
接下来就是添加服务与中间件了
打开stratup类,在ConfigureServices方法中添加json
services.AddMvc();注册服务bootstrap
在Configure方法
去掉
app.Run(async (context) =>
{
await context.Response.WriteAsync(“Hello World!”);
});浏览器
添加默认路由
app.UseMvc(routes =>
{
//默认路由:没有指定url和controller状况下会默认找到下面这个
routes.MapRoute(
name: “default”,
template: “{controller=Home}/{action=Index}/{id?}”);
});app
打开launchSettings.json,把这个去掉,可直接打开控制台
asp.net
打开浏览器输入localhost:5000async
却发现什么都没
而后在Configure方法添加
//显示错误
app.UseStatusCodePages();
//加载wwwroot文件夹下css,js
app.UseStaticFiles()
这两个方法,做用都备注了;
再运行,输入网址
这个是默认显示的错误
还能够本身添加自定义错误输出
app.UseStatusCodePagesWithRedirects();
这里就不用了
stratup类代码
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DemoCoreStudy.Serivce; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; namespace DemoCoreStudy { public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSingleton<ICinemaService, CinemaMemoryService>(); services.AddSingleton<IMovieService, MovieMemoryService>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //显示错误 //app.UseStatusCodePages(); //添加自定义错误 //app.UseStatusCodePagesWithRedirects(); //加载wwwroot文件夹下css,js app.UseStaticFiles(); app.UseMvc(routes => { //默认路由:没有指定url和controller状况下会默认找到下面这个 routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } }
下一篇博客
https://blog.csdn.net/qq_41841878/article/details/85496219