国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

asp.net core項(xiàng)目中如何使用html文件

2024-07-10 12:48:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

前言

大家應(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ì)錯(cuò)新站長(zhǎng)站的支持。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 当涂县| 邮箱| 古蔺县| 阿合奇县| 中江县| 云霄县| 临颍县| 鄂托克前旗| 子洲县| 来宾市| 宜章县| 长白| 厦门市| 措勤县| 榆社县| 连云港市| 湟中县| 鲁甸县| 乐山市| 湘乡市| 东阳市| 安康市| 防城港市| 宜春市| 黄浦区| 偏关县| 陇川县| 孟津县| 壶关县| 潍坊市| 石棉县| 云林县| 嘉兴市| 东至县| 怀集县| 河津市| 昌吉市| 兴仁县| 微山县| 安西县| 广河县|