asp.net core項(xiàng)目中如何使用html文件
前言
大家應(yīng)該都知道,在asp.net core 項(xiàng)目中,使用html文件一般通過(guò)使用中間件來(lái)提供服務(wù):
打開(kāi) NuGet程序管理控制臺(tái)
輸入install-package Microsoft.aspnetcore.staticfiles 進(jìn)行添加
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>進(jìn)入百度</em></a> </body> </html>
修改Index.cshtml,添加訪問(wèn)鏈接
@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>
運(yùn)行MyWeb在Index首頁(yè)進(jìn)行訪問(wèn)
或者輸入地址http://localhost:端口號(hào)/Baidu.html
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
- 詳解ASP.NET Core WebApi 返回統(tǒng)一格式參數(shù)
- ASP.NET Core DI手動(dòng)獲取注入對(duì)象的方法
- ASP.NET Core2讀寫InfluxDB時(shí)序數(shù)據(jù)庫(kù)的方法教程
- ASP.NET Core使用自定義驗(yàn)證屬性控制訪問(wèn)權(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自動(dòng)化發(fā)布與部署的實(shí)現(xiàn)
- 淺談從ASP.NET Core2.2到3.0你可能會(huì)遇到這些問(wèn)題
相關(guān)文章
asp.net使用ODP即oracle連接方式的的防注入登錄驗(yàn)證程序
這篇文章主要介紹了asp.net使用ODP即oracle連接方式的的防注入登錄驗(yàn)證程序,需要的朋友可以參考下2014-05-05
gridview checkbox從服務(wù)器端和客戶端兩個(gè)方面實(shí)現(xiàn)全選和反選
GridView中的checkbox的全選和反選在很多的地方都是要求實(shí)現(xiàn)的,所以下面就從服務(wù)器端和客戶端兩個(gè)方面實(shí)現(xiàn)了checkbox的選擇,感興趣的朋友可以了解下,希望本文對(duì)你有所幫助2013-01-01
詳解Spring Boot 中使用 Java API 調(diào)用 lucene
這篇文章主要介紹了詳解Spring Boot 中使用 Java API 調(diào)用 lucene,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
asp.net mvc 動(dòng)態(tài)編譯生成Controller的方法
本篇文章主要介紹了asp.net mvc 動(dòng)態(tài)編譯生成Controller的方法,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08
ASP.NET文件上傳Upload的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了ASP.NET文件上傳的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11

