1. 程式人生 > >dotnet core 開發中遇到的問題

dotnet core 開發中遇到的問題

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"