当前位置: 首页 > news >正文

漳州做网站建设建网站免费

漳州做网站建设,建网站免费,动效h5网站,一般做企业网站多少钱Static Files Static Files 包括 HTML,CSS,图片,JavaScript,以及其他静态资源文件。 即网站本身的内容。 Static Files 服务 Static Files 保存在项目的 Web Root 目录,即 wwwroot 文件夹中。 而wwwroot目录是Conte…

Static Files

Static Files 包括 HTML,CSS,图片,JavaScript,以及其他静态资源文件。
即网站本身的内容。

Static Files 服务

Static Files 保存在项目的 Web Root 目录,即 wwwroot 文件夹中。
而wwwroot目录是Content Root 的子目录, Content Root 还包括其他代码文件,.exe 和 .dll 文件。
wwwroot文件夹的结构如下:

  • css
  • js
  • lib
  • images
    • 1.jpg

在App启动时调用UseStaticFiles启用静态文件service后,会将wwwroot 目录映射到 https:///

app.UseStaticFiles();

可以通过url https://localhost:5001/images/1.jpg 访问这个图片文件。

映射其他目录

如果想将其他目录映射到 https:///otherroot/images/1.jpg,比如

  • wwwroot
    • css
    • images
    • js
  • otherroot
    • images
      • 1.jpg

可以这样映射:

app.UseStaticFiles(new StaticFileOptions
{FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "otherroot")),RequestPath = "/otherroot",OnPrepareResponse = ctx =>{var cacheMaxAgeOneWeek = (60 * 60 * 24 * 7).ToString();ctx.Context.Response.Headers.Append("Cache-Control", $"public, max-age={cacheMaxAgeOneWeek}"); //添加过期时间}
});

然后在html代码中可以这样引用:

<img src="~/otherroot/images/1.png" class="img" asp-append-version="true" alt="Test">

设置 Static Files 的访问权限

需要满足3个条件:

  • 不保存在wwwroot下
  • 先调用UseAuthorization,再调用UseStaticFiles
  • 设置 fallback authorization 策略
builder.Services.AddAuthorization(options =>
{options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
});

以禁止匿名访问这些文件。

列出文件目录

Directory Browsing 服务可以列出某个目录下的所有文件。
可以通过 AddDirectoryBrowser()启用:

builder.Services.AddDirectoryBrowser();
var fileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.WebRootPath, "MyImages"));
var requestPath = "/MyImages";
app.UseDirectoryBrowser(new DirectoryBrowserOptions
{FileProvider = fileProvider,RequestPath = requestPath
});

使用默认文件

使用app.UseDefaultFiles()后,

app.UseDefaultFiles();

会在wwwroot 下依次查找这些文件作为入口

  • default.htm
  • default.html
  • index.htm
  • index.html

也可以指定文件名mydefault.html:

var options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("mydefault.html");
app.UseDefaultFiles(options);

UseFileServer

app.UseFileServer 是 UseStaticFiles,UseDefaultFiles 或者 UseDirectoryBrowser的组合。

builder.Services.AddDirectoryBrowser();
app.UseFileServer(enableDirectoryBrowsing: true);

上面的代码会启用UseStaticFiles,UseDefaultFiles,和DirectoryBrowsing。

FileExtensionContentTypeProvider

FileExtensionContentTypeProvider 的 Mappings 属性可以将文件扩展名 映射到 MIME Content Types。

// Set up custom content types - associating file extension to MIME type
var provider = new FileExtensionContentTypeProvider();
// Add new mappings
provider.Mappings[".myapp"] = "application/x-msdownload";
provider.Mappings[".htm3"] = "text/html";
provider.Mappings[".image"] = "image/png";
// Replace an existing mapping
provider.Mappings[".rtf"] = "application/x-msdownload";
// Remove MP4 videos.
provider.Mappings.Remove(".mp4");
app.UseStaticFiles(new StaticFileOptions
{ContentTypeProvider = provider
});
http://www.hkea.cn/news/733498/

相关文章:

  • 网站建设服务上海广州软文推广公司
  • 做一个网站app需要多少钱web制作网站的模板
  • 网站建设的财务计划新媒体营销策略有哪些
  • 网站建设分金手指专业二八宁波品牌网站推广优化
  • 清远网站建设公司百度游戏风云榜
  • 网上可以自学什么技术win7系统优化软件
  • 嘉兴建站软件如何做好企业网站的推广
  • 在凡科做网站短视频推广
  • 深圳推广公司推荐q群排名优化软件
  • 什么网站做简历模板宁德市医院
  • 用什么软件做公司网站游戏推广赚佣金的平台
  • 购物网站 后台模板河北seo技术培训
  • 聊城建设委员会官方网站google seo
  • 广西建设网郭业棚seo推广具体做什么
  • 武汉网站seo诊断谷歌下载官网
  • 做地方网站能赚钱吗免费seo网站诊断
  • 图片设计在线网站推广优化外包便宜
  • 武汉平价做网站网络软文推广案例
  • 新产品线上推广方案鞍山seo外包
  • 网站建网站建设和优佛山网络推广培训
  • 毕业设计做网站怎么样微信crm管理系统
  • 个人网站开发多少钱电脑培训班零基础
  • 互联网有哪些岗位宁波免费seo在线优化
  • 惠州做棋牌网站建设哪家技术好哪里的网络推广培训好
  • 如何做线上赌博的网站推广策略有哪些方法
  • 男的女的做那个视频网站百度收录需要多久
  • 大通县wap网站建设公司网站免费制作
  • 哪个网站教做公众号甘肃百度推广电话
  • 网站怎么让百度收录广告网络推广
  • 小型网站设计及建设论文定制网站制作公司