asp.net core項目中如何使用html文件
前言
大家應(yīng)該都知道,在asp.net core 項目中,使用html文件一般通過使用中間件來提供服務(wù):
打開 NuGet程序管理控制臺
輸入install-package Microsoft.aspnetcore.staticfiles
進行添加
ASP.NET Core static files middleware. Includes middleware for serving static files, directory browsing, and default files
.
在Startup.cs中使用服務(wù):
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; namespace MyWeb { 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(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseStaticFiles(); app.UseMvc(); } } }
在wwwroot下添加Baidu.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Baidu</title> </head> <body> <a target="_self"><em>進入百度</em></a> </body> </html>
修改Index.cshtml,添加訪問鏈接
@page @model MyWeb.Pages.IndexModel @{ ViewData["Title"] = "Index"; } <h2>Index</h2> <a href="Index2">Index2</a> <a href="Baidu.html" target="_self">Baidu</a> <hr /> <a href="Customers">CustomersIndex</a> <h1>Hello, world!</h1> <h2>The time on the server is @DateTime.Now</h2>
運行MyWeb在Index首頁進行訪問
或者輸入地址http://localhost:端口號/Baidu.html
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- 詳解ASP.NET Core WebApi 返回統(tǒng)一格式參數(shù)
- ASP.NET Core DI手動獲取注入對象的方法
- ASP.NET Core2讀寫InfluxDB時序數(shù)據(jù)庫的方法教程
- ASP.NET Core使用自定義驗證屬性控制訪問權(quán)限詳解
- ASP.NET Core Mvc中空返回值的處理方法詳解
- asp.net core集成MongoDB的完整步驟
- Asp.NET Core 如何調(diào)用WebService的方法
- ASP.NET Core Web App應(yīng)用第三方Bootstrap模板的方法教程
- Centos7+Docker+Jenkins+ASP.NET Core 2.0自動化發(fā)布與部署的實現(xiàn)
- 淺談從ASP.NET Core2.2到3.0你可能會遇到這些問題
相關(guān)文章
asp.net在iframe中彈出信息并執(zhí)行跳轉(zhuǎn)問題探討
本代碼將實現(xiàn)在iframe中彈出信息并執(zhí)行跳轉(zhuǎn),感興趣的朋友可以參考下2013-04-04前臺JS(jquery ajax)調(diào)用后臺方法實現(xiàn)無刷新級聯(lián)菜單示例
前臺用AJAX直接調(diào)用后臺方法,老有人發(fā)帖提問,沒事做個示例詳細介紹一下,感興趣的朋友可以參考下2013-01-01FileUpload使用Javascript檢查擴展名是否有效實現(xiàn)思路
在JavaScript獲取FileUpload控件的文件路徑,并取得路徑中的文件擴展名,再與陣列中的擴展名比較,如果存在,說明上傳的文件是有效的,反之無效,感興趣的朋友可以了解下,或許對你有所幫助2013-02-02Asp.net頁面中調(diào)用soapheader進行驗證的操作步驟
這篇文章主要介紹了Asp.net頁面中調(diào)用soapheader進行驗證的操作步驟,感興趣的小伙伴們可以參考一下2016-04-04asp.net內(nèi)置對象 Response對象使用介紹
這篇文章主要介紹了asp.net內(nèi)置對象:Response對象使用介紹,對Response對象感興趣的小伙伴們可以參考一下2015-11-11IIS中ASP.NET連接SQL Server出錯的解決方法
在IIS中運行的ASP.NET應(yīng)用程序其所屬用戶名為ASPNET的特定用戶,其默認權(quán)限是無法訪問SQL Server的,更不可能訪問ASP.NET應(yīng)用程序的數(shù)據(jù)庫了,因此要在IIS中訪問SQL Server就需要給ASPNET帳戶賦予相應(yīng)的權(quán)限.2010-03-03