dotnet core 開發中遇到的問題

一、發佈的時候把視圖cshtml文件也編譯爲dll了,如何控制不編譯視圖?css

  編輯功能文件(xx.csproj),加入一個選項:         html

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
  </PropertyGroup>

 

二、網站裏面有 .less等靜態資源文件 dotnet core 默認是不容許訪問的,如何解決呢linux

  在startup的Configure方法中加入文件擴展的提供程序,例如:
  
cookie

 var Provider = new FileExtensionContentTypeProvider();
            Provider.Mappings[".less"] = "text/css";
            app.UseStaticFiles(new StaticFileOptions()
            {
                ContentTypeProvider = Provider
            });

 

三、多cookie登陸如何配置呢?app

  在startup的 ConfigureServices方法中加入如下代碼:less

     

//添加認證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,例如:
 ide

 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));

 

四、多個Areas的站點 發佈後在window下能夠而linux不行,找不到區域下的視圖網站

  通常是區域的名稱設置的大小寫的問題,我遇到的問題是 個人程序裏面區域是這樣定義的  [Area("Admin")],而我發佈後區域視圖文件夾是 admin 因此找不到url

五、dotnet core 命令行啓動的時候如何用默認的端或者指定端口呢?spa

     dotnet xx.dll urls="http://*:80"

相關文章
相關標籤/搜索