受欢迎的博客标签

ASP.NET Core实战记录:asp net core改变缺省wwwroot到制定目录和指定目录浏览

Published

1.asp net core改变缺省wwwroot到制定目录和指定目录浏览

//改变缺省wwwroot到制定目录

app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "Themes", "BootStrap4")), RequestPath = new PathString("") });

//指定目录浏览

app.UseDirectoryBrowser(new DirectoryBrowserOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "images")), RequestPath = new PathString("/MyImages") });

http://www.iaspnetcore.com/images可以浏览目录了

2.netstandard2.0 

(1)  no [Display()]

you must nuget System.ComponentModel.DataAnnotations;

and nuget System.ComponentModel;

using System.ComponentModel.DataAnnotations;

namespace MailSpider.Services.BaiduyunDisk { /// /// 爬虫爬取过程中json返回错误码 /// public enum SpiderErrorType { /// /// 爬取正常 /// [Display(Name = "爬取正常")] ERR_NO =(int) 0, /// /// 爬虫爬取速度过快,被拒绝 /// [Display(Name = "爬虫爬取速度过快,被拒绝")] ERR_REFUSE = (int)-55, /// /// 爬虫爬取未知错误 /// [Display(Name = "爬虫爬取未知错误")] RR_EX = (int)5 } }

(2) no HeaderNames

you must Nuget Microsoft.Net.Http.Headers;  

using Microsoft.Net.Http.Headers;

namespace MailSpider.Services.BaiduyunDisk { client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.Accept, "application/json,text/javascript,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); client.DefaultRequestHeaders.TryAddWithoutValidation("X-Requested-With", "XMLHttpRequest"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.AcceptEncoding, "gzip, deflate, sdch"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.AcceptLanguage, "zh-CN,zh;q=0.8,en;q=0.6"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.CacheControl, "max-age=0"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.Connection, "keep-alive"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.Cookie, "Cookie: SFSSID=gh5dben3oh6m3iu8t5le7eee34; PANWEB=1; BAIDUID=1D3F7F7AD0D82AA1A6132F804AA5615F:FG=1; FP_UID=bc626b1b3fb4a73098a5ec2fd82d4b14; panlogin_animate_showed=1; FP_LASTTIME=1503790283830; pan_login_way=1; bdshare_firstime=1503794939610; Hm_lvt_f5f83a6d8b15775a02760dc5f490bc47=1503850117; Hm_lpvt_f5f83a6d8b15775a02760dc5f490bc47=1504193455; Hm_lvt_e6c5e9705447b840241ebab6dbdb5fda=1503514321,1504196091; Hm_lpvt_e6c5e9705447b840241ebab6dbdb5fda=1504196091; BIDUPSID=1D3F7F7AD0D82AA1A6132F804AA5615F; PSTM=1504196810; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; PSINO=7; H_PS_PSSID=1449_21121_20697_20719; cflag=15%3A3; BDUSS=Th1MGtUNEFlYm5wSmcwc0x4Tlg0MTB6UzdGb2RVSlg2OEEtd09WWHRRakh2ZEpaSVFBQUFBJCQAAAAAAAAAAAEAAACONC0BZnJlZXd6eAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMcwq1nHMKtZS; STOKEN=7ea43ef2d91177c364ee734380ed3dca0526aa19ef9dd075beff47bf3af9295c; SCRC=f4cbc58fcb4cb01a48894298bac05d68; Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1503781299,1504196800; Hm_lpvt_7a3960b6f067eb0085b7f96ff5e660b0=1504391238; PANPSC=8637655925612390685%3Apg%2B1B8fqOSd7%2B1YWoRpprs5gl74Q7yn69KU9cgyzyILxTJ3v1z1m%2BgBm5%2FBKjlRyjuz2rt3cpYP8UpyRewef%2FHbJG1pZy3HIgs6%2BSP%2BysvhAATKJ67z9uS3YfH0dr9bYA8yxsQhfco3IUyrvncE2%2F56%2FckKAnhyPPINT3EXK3IjGdPa0DtmINb3bwxtQHr5H"); client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.UserAgent, "keep-alive"); }

3.同一解决方案下多个网站公共菜单部分

2.1 方式一:外部ViewComponent

写一个外部ViewComponent类库WEBAPP,然后利用TagHelper 引用

2.2 方式二:外部ViewComponent

LOADING VIEW COMPONENTS FROM A CLASS LIBRARY IN ASP.NET CORE MVC

2.3 方式三:TagHelper直接写一个TagHelper,然后引用

2.4 方式四:Razor Page LibraryRazor Page Library 输出为字符串   .