1、發佈的時候把視圖cshtml文件也編譯為dll了,如何控制不編譯視圖? 編輯功能文件(xx.csproj),加入一個選項: 2、網站裡面有 .less等靜態資源文件 dotnet core 預設是不允許訪問的,如何解決呢 在startup的Configure方法中加入文件擴展的提供程式,例如: ...
1、發佈的時候把視圖cshtml文件也編譯為dll了,如何控制不編譯視圖?
編輯功能文件(xx.csproj),加入一個選項:
<PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish> </PropertyGroup>
2、網站裡面有 .less等靜態資源文件 dotnet core 預設是不允許訪問的,如何解決呢
在startup的Configure方法中加入文件擴展的提供程式,例如:
var Provider = new FileExtensionContentTypeProvider(); Provider.Mappings[".less"] = "text/css"; app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = Provider });
3、多cookie登錄如何配置呢?
在startup的 ConfigureServices方法中加入以下代碼:
//添加認證Cookie信息 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme + "_client", options => { options.LoginPath = new PathString("/login"); options.AccessDeniedPath = new PathString("/tool"); }) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.LoginPath = new PathString("/admin/login"); options.AccessDeniedPath = new PathString("/Admin"); });
註意主要使用AuthenticationScheme 區分不同cookie的,所有在登錄的時候也要用相應的 AuthenticationScheme,例如:
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme+"_client"); identity.AddClaim(new Claim(ClaimTypes.Sid, userEntity.LoginName)); identity.AddClaim(new Claim(ClaimTypes.Name, userEntity.LoginName)); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme+"_client", new ClaimsPrincipal(identity));
4、多個Areas的站點 發佈後在window下可以而linux不行,找不到區域下的視圖
一般是區域的名稱設置的大小寫的問題,我遇到的問題是 我的程式裡面區域是這樣定義的 [Area("Admin")],而我發佈後區域視圖文件夾是 admin 所以找不到
5、dotnet core 命令行啟動的時候如何用預設的端或者指定埠呢?
dotnet xx.dll urls="http://*:80"