asp.net core項(xiàng)目中如何使用html文件
前言
大家應(yīng)該都知道,在asp.net core 項(xiàng)目中,使用html文件一般通過(guò)使用中間件來(lái)提供服務(wù):
打開 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在iframe中彈出信息并執(zhí)行跳轉(zhuǎn)問(wèn)題探討
本代碼將實(shí)現(xiàn)在iframe中彈出信息并執(zhí)行跳轉(zhuǎn),感興趣的朋友可以參考下2013-04-04
asp.net 擴(kuò)展GridView 增加單選按鈕列的代碼
asp.net 擴(kuò)展GridView 增加單選按鈕列的代碼2010-02-02
前臺(tái)JS(jquery ajax)調(diào)用后臺(tái)方法實(shí)現(xiàn)無(wú)刷新級(jí)聯(lián)菜單示例
前臺(tái)用AJAX直接調(diào)用后臺(tái)方法,老有人發(fā)帖提問(wèn),沒(méi)事做個(gè)示例詳細(xì)介紹一下,感興趣的朋友可以參考下2013-01-01
FileUpload使用Javascript檢查擴(kuò)展名是否有效實(shí)現(xiàn)思路
在JavaScript獲取FileUpload控件的文件路徑,并取得路徑中的文件擴(kuò)展名,再與陣列中的擴(kuò)展名比較,如果存在,說(shuō)明上傳的文件是有效的,反之無(wú)效,感興趣的朋友可以了解下,或許對(duì)你有所幫助2013-02-02
Asp.net頁(yè)面中調(diào)用soapheader進(jìn)行驗(yàn)證的操作步驟
這篇文章主要介紹了Asp.net頁(yè)面中調(diào)用soapheader進(jìn)行驗(yàn)證的操作步驟,感興趣的小伙伴們可以參考一下2016-04-04
asp.net內(nèi)置對(duì)象 Response對(duì)象使用介紹
這篇文章主要介紹了asp.net內(nèi)置對(duì)象:Response對(duì)象使用介紹,對(duì)Response對(duì)象感興趣的小伙伴們可以參考一下2015-11-11
IIS中ASP.NET連接SQL Server出錯(cuò)的解決方法
在IIS中運(yùn)行的ASP.NET應(yīng)用程序其所屬用戶名為ASPNET的特定用戶,其默認(rèn)權(quán)限是無(wú)法訪問(wèn)SQL Server的,更不可能訪問(wèn)ASP.NET應(yīng)用程序的數(shù)據(jù)庫(kù)了,因此要在IIS中訪問(wèn)SQL Server就需要給ASPNET帳戶賦予相應(yīng)的權(quán)限.2010-03-03

