ASP.NET Core2.0項目實戰-003

Views

佈局(Layouts)

視圖組件(ViewComponents)

分部視圖(PartialViews)

HTML助手(HtmlHelpers)   頁面標籤的輔助類

Tag助手(TagHelpers)

配置全部視圖(Global view configutation)

視圖找的時候如果home裏面沒有還會找shared文件夾裏面的

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;

namespace KevinTest001
{
    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)
        {
            //#Kevin 添加一些服務 把和MVC相關的服務都添加一下
            services.AddMvc();
        }

        // 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();
            }
            //#Kevin y允許使用靜態文件
            // app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions() {
                //#Kevin 寫個目錄  獲取當前根目錄
                //  FileProvider =new PhysicalFileProvider(Directory.GetCurrentDirectory())   //這樣的就所有的根目錄下都能訪問,這樣不太好

                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Images")),  //#Kevin 只能限定在Images文件夾下。
                RequestPath = new PathString("/Images")

            });

            //#Kevin 添加路由,讓程序能找到控制器、找到方法、找到   默認路由,什麼都不輸入的時候找home的index方法
            app.UseMvcWithDefaultRoute();

            

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章