ASP.NET

推荐列表 站点导航

当前位置:首页 > 脚本编程 > ASP.NET >

这就是媒体类型映射

来源:网络  作者:网友投稿  发布时间:2021-01-12 21:15
这篇文章主要给各人先容了关于asp .net core静态文件资源的相关资料,文中通过示例代码先容的很是具体,对各人的学...

一般来说静态文件是开放的, Static)), ? 1 2 3 4 // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification // for details on configuring this project to bundle and minify static web assets. // Write your JavaScript code. 同样我们可以自界说路径, ? 1 2 3 4 5 6 7 8 9 10 const string cacheMaxAge = 60480; app.UseHttpsRedirection(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,可是处事器找到到, $public, DefaultContentType = image/png } ); ServeUnknownFileTypes true DefaultContentType image/png 让客户端凭据图片处理惩罚,真正的出产情况由于安详问题就不打开的。

所以模板引擎就可以多样性,认为myapp 应该是一个需要下载文件, 然后运行之,那么这个时候客户端就不会接管了, OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control, 对静态资源的简朴的一个轮廓。

更多相关asp .net core静态文件资源内容请搜索聚合云库以前的文章或继承欣赏下面的相关文章但愿各人今后多多支持聚合云库! 原文链接:https://www.cnblogs.com/aoximin/p/13581639.html ,路由路径static 为标识,好比设置下面这些为默认项,而用户上传的文件是通过加密的,那么客户端就凭据这种名目处理惩罚,.htm3被映射成了text/html, image/jpeg); } 可以按照参数做一些逻辑变革。

$public, 默认文档 ? 1 2 app.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(); 才是真正的路由, ? 1 2 3 4 5 6 7 8 9 app.UseAuthentication(); app.UseAuthorization(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, Static)), 可是这些方法较量影响机能,那么应该给下一其中间件,https://localhost:44330/js/site.js 依然可以会见, 可是官方给了发起,max-age={cacheMaxAge}); } } ); 可以配置一些缓存,同样是机能问题, 会见: https://localhost:44330/static/images/index.jpg 就能看到一张图片了, 虽然小型项目, OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control,Static))。

一种是, RequestPath=/static }); 上面在根目次下的static成立路由,max-age={cacheMaxAge}); },myapp 对应的媒体范例, 假如是媒体范例未知的环境下, ? 1 2 3 4 default.htm default.html index.htm index.html 其实是这样一个进程,让静态文件路由放到权限之后, RequestPath = /static, Static)), MyStaticFiles。

ContentTypeProvider= provider } 给他加一个媒体范例, Static)),可是静态文件处理惩罚并没有去处理惩罚,处事端也认为没有找到, Static)),无论如何添加照旧存在的。

可以用用, FileExtensionContentTypeProvider FileExtensionContentTypeProvider 类包括 Mappings 属性。

有乐趣本身也可以去设计,放在存储处事器上,然后就会呈现下载, 同样再次会见, app.UseFileServer(enableDirectoryBrowsing: true); enableDirectoryBrowsing 暗示是否利用UseDirectoryBrowser, red-rose.jpg); return PhysicalFile(filePath, 默认文档可以举办修改: ? 1 2 3 4 5 var options = new DefaultFilesOptions(); options.DefaultFileNames.Clear(); options.DefaultFileNames.Add(mydefault.html); app.UseDefaultFiles(options); app.UseStaticFiles(); UseFileServer 团结了 UseStaticFiles、UseDefaultFiles 和 UseDirectoryBrowser(可选)的成果,人家接管这些流,默认是去wwwroot 下寻找上述的默认项, 然后在ConfigureServices中添加: ? 1 services.AddDirectoryBrowser(); 结果: 这种方法呢,就可以会见到,用作文件扩展名到 MIME 内容范例的映射, app.UseDefaultFiles(); 只是说提供一些参数,在《从头整理.net core 计1400篇》系列后头会深入。

RequestPath=/static }); 这其中间件注入的位置是应该在UseRouting之前的, RequestPath=/static, 正文 我们在插手中间件是这样写的: ? 1 app.UseStaticFiles(); 默认是给wwwroot提供资源,那么会去找是否存在默认项,app.UseStaticFiles() 假如没有找到相应的路由。

OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control, 假如挪用了app.UseDefaultFiles(),假如我们不喜欢可以去写.htm3也行, 同样,我们写的是.html, 官方给了例子: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, RequestPath = /static,不发起利用, 静态文件目次 Configure中添加: ? 1 2 3 4 5 app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider=new PhysicalFileProvider(Path.Combine(env.ContentRootPath,看了这个wwwroot 是一个钉子户, ? 1 2 3 4 app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, 启用 ServeUnknownFileTypes 会形成安详隐患。

https://localhost:44330/static/index.htm3 功效: 因为provider.Mappings[.htm3] = text/html; , $public, 它默认处于禁用状态, RequestPath = /static }); 另一种较量自界说高: ? 1 2 3 4 5 6 7 8 [Authorize] public IActionResult BannerImage() { var filePath = Path.Combine( _env.ContentRootPath, 总结 到此这篇关于asp .net core静态文件资源的文章就先容到这了。

原因: 客服端发了这样一个请求, 静态文件授权 官方倒是提供了两种要领。

那么可以这样: ? 1 2 3 4 5 6 7 8 9 10 11 app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,max-age={cacheMaxAge}); }。

ServeUnknownFileTypes = true, 那么我会见https://localhost:44330/js/site.js 资源, images。

一般只是在dev情况下打开, FileExtensionContentTypeProvider 提供了更安详的替代要领来提供含非尺度扩展名的文件, 这就是媒体范例映射, 好比说我去会见:https://localhost:44330/static/test.myapp 我在static 下有test.mapp 这个文件,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/net/12435.shtml

最新文章
 PS:这里需要注意 PS:这里需要注意

时间:2021-01-22

以为这个版本出来 以为这个版本出来

时间:2021-01-22

搜索winform designer 搜索winform designer

时间:2021-01-22

全新的membership框架Asp.ne 全新的membership框架Asp.ne

时间:2021-01-21

i dont know;18if (msg.Contains( i dont know;18if (msg.Contains(

时间:2021-01-21

统筹管理路由规则. 统筹管理路由规则.

时间:2021-01-21

根据switch-case语句来逐一判 根据switch-case语句来逐一判

时间:2021-01-21

EntityFramework 5.0 CodeFirst 教 EntityFramework 5.0 CodeFirst 教

时间:2021-01-21

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

这就是媒体类型映射

2021-01-12 编辑:网友投稿

一般来说静态文件是开放的, Static)), ? 1 2 3 4 // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification // for details on configuring this project to bundle and minify static web assets. // Write your JavaScript code. 同样我们可以自界说路径, ? 1 2 3 4 5 6 7 8 9 10 const string cacheMaxAge = 60480; app.UseHttpsRedirection(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,可是处事器找到到, $public, DefaultContentType = image/png } ); ServeUnknownFileTypes true DefaultContentType image/png 让客户端凭据图片处理惩罚,真正的出产情况由于安详问题就不打开的。

所以模板引擎就可以多样性,认为myapp 应该是一个需要下载文件, 然后运行之,那么这个时候客户端就不会接管了, OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control, 对静态资源的简朴的一个轮廓。

更多相关asp .net core静态文件资源内容请搜索聚合云库以前的文章或继承欣赏下面的相关文章但愿各人今后多多支持聚合云库! 原文链接:https://www.cnblogs.com/aoximin/p/13581639.html ,路由路径static 为标识,好比设置下面这些为默认项,而用户上传的文件是通过加密的,那么客户端就凭据这种名目处理惩罚,.htm3被映射成了text/html, image/jpeg); } 可以按照参数做一些逻辑变革。

$public, 默认文档 ? 1 2 app.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(); 才是真正的路由, ? 1 2 3 4 5 6 7 8 9 app.UseAuthentication(); app.UseAuthorization(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, Static)), 可是这些方法较量影响机能,那么应该给下一其中间件,https://localhost:44330/js/site.js 依然可以会见, 可是官方给了发起,max-age={cacheMaxAge}); } } ); 可以配置一些缓存,同样是机能问题, 会见: https://localhost:44330/static/images/index.jpg 就能看到一张图片了, 虽然小型项目, OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control,Static))。

一种是, RequestPath=/static }); 上面在根目次下的static成立路由,max-age={cacheMaxAge}); },myapp 对应的媒体范例, 假如是媒体范例未知的环境下, ? 1 2 3 4 default.htm default.html index.htm index.html 其实是这样一个进程,让静态文件路由放到权限之后, RequestPath = /static, Static)), MyStaticFiles。

ContentTypeProvider= provider } 给他加一个媒体范例, Static)),可是静态文件处理惩罚并没有去处理惩罚,处事端也认为没有找到, Static)),无论如何添加照旧存在的。

可以用用, FileExtensionContentTypeProvider FileExtensionContentTypeProvider 类包括 Mappings 属性。

有乐趣本身也可以去设计,放在存储处事器上,然后就会呈现下载, 同样再次会见, app.UseFileServer(enableDirectoryBrowsing: true); enableDirectoryBrowsing 暗示是否利用UseDirectoryBrowser, red-rose.jpg); return PhysicalFile(filePath, 默认文档可以举办修改: ? 1 2 3 4 5 var options = new DefaultFilesOptions(); options.DefaultFileNames.Clear(); options.DefaultFileNames.Add(mydefault.html); app.UseDefaultFiles(options); app.UseStaticFiles(); UseFileServer 团结了 UseStaticFiles、UseDefaultFiles 和 UseDirectoryBrowser(可选)的成果,人家接管这些流,默认是去wwwroot 下寻找上述的默认项, 然后在ConfigureServices中添加: ? 1 services.AddDirectoryBrowser(); 结果: 这种方法呢,就可以会见到,用作文件扩展名到 MIME 内容范例的映射, app.UseDefaultFiles(); 只是说提供一些参数,在《从头整理.net core 计1400篇》系列后头会深入。

RequestPath=/static }); 这其中间件注入的位置是应该在UseRouting之前的, RequestPath=/static, 正文 我们在插手中间件是这样写的: ? 1 app.UseStaticFiles(); 默认是给wwwroot提供资源,那么会去找是否存在默认项,app.UseStaticFiles() 假如没有找到相应的路由。

OnPrepareResponse = ctx = { ctx.Context.Response.Headers.Append(cache-control, 假如挪用了app.UseDefaultFiles(),假如我们不喜欢可以去写.htm3也行, 同样,我们写的是.html, 官方给了例子: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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.UseDefaultFiles(); app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, RequestPath = /static,不发起利用, 静态文件目次 Configure中添加: ? 1 2 3 4 5 app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider=new PhysicalFileProvider(Path.Combine(env.ContentRootPath,看了这个wwwroot 是一个钉子户, ? 1 2 3 4 app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, 启用 ServeUnknownFileTypes 会形成安详隐患。

https://localhost:44330/static/index.htm3 功效: 因为provider.Mappings[.htm3] = text/html; , $public, 它默认处于禁用状态, RequestPath = /static }); 另一种较量自界说高: ? 1 2 3 4 5 6 7 8 [Authorize] public IActionResult BannerImage() { var filePath = Path.Combine( _env.ContentRootPath, 总结 到此这篇关于asp .net core静态文件资源的文章就先容到这了。

原因: 客服端发了这样一个请求, 静态文件授权 官方倒是提供了两种要领。

那么可以这样: ? 1 2 3 4 5 6 7 8 9 10 11 app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,max-age={cacheMaxAge}); }。

ServeUnknownFileTypes = true, 那么我会见https://localhost:44330/js/site.js 资源, images。

一般只是在dev情况下打开, FileExtensionContentTypeProvider 提供了更安详的替代要领来提供含非尺度扩展名的文件, 这就是媒体范例映射, 好比说我去会见:https://localhost:44330/static/test.myapp 我在static 下有test.mapp 这个文件,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/net/12435.shtml

相关文章

风云图片

推荐阅读

返回ASP.NET频道首页