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"

相关文章
相关标签/搜索