asp.net core項目中如何使用html文件
前言
大家應該都知道,在asp.net core 項目中,使用html文件一般通過使用中間件來提供服務:
打開 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中使用服務:
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
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- 詳解ASP.NET Core WebApi 返回統(tǒng)一格式參數(shù)
- ASP.NET Core DI手動獲取注入對象的方法
- ASP.NET Core2讀寫InfluxDB時序數(shù)據(jù)庫的方法教程
- ASP.NET Core使用自定義驗證屬性控制訪問權限詳解
- ASP.NET Core Mvc中空返回值的處理方法詳解
- asp.net core集成MongoDB的完整步驟
- Asp.NET Core 如何調(diào)用WebService的方法
- ASP.NET Core Web App應用第三方Bootstrap模板的方法教程
- Centos7+Docker+Jenkins+ASP.NET Core 2.0自動化發(fā)布與部署的實現(xiàn)
- 淺談從ASP.NET Core2.2到3.0你可能會遇到這些問題
相關文章
asp.net使用ODP即oracle連接方式的的防注入登錄驗證程序
這篇文章主要介紹了asp.net使用ODP即oracle連接方式的的防注入登錄驗證程序,需要的朋友可以參考下2014-05-05
gridview checkbox從服務器端和客戶端兩個方面實現(xiàn)全選和反選
GridView中的checkbox的全選和反選在很多的地方都是要求實現(xiàn)的,所以下面就從服務器端和客戶端兩個方面實現(xiàn)了checkbox的選擇,感興趣的朋友可以了解下,希望本文對你有所幫助2013-01-01
詳解Spring Boot 中使用 Java API 調(diào)用 lucene
這篇文章主要介紹了詳解Spring Boot 中使用 Java API 調(diào)用 lucene,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
asp.net mvc 動態(tài)編譯生成Controller的方法
本篇文章主要介紹了asp.net mvc 動態(tài)編譯生成Controller的方法,具有一定的參考價值,有興趣的可以了解一下2017-08-08

