简体   繁体   中英

Identity project updated to Asp.Net Core 3 gives wwwroot folder

I have an asp.net core 2.2.6 web api project. No views, no script files, no css nothing. I just upgraded it to asp.net core 3.1 and when I publish using release build I see a wwwroot folder containing css,js and lib folders containing css and js files.

How can I remove them since I don't see them anywhere in my solution? Here is the code for adding identity:

Update #1

services.AddDefaultIdentity<ApplicationUser>(options =>
{
    options.SignIn.RequireConfirmedEmail = true;
    options.Password.RequireDigit = true;
    options.Password.RequireLowercase = true;
    options.Password.RequireNonAlphanumeric = true;
    options.Password.RequireUppercase = true;
    options.Password.RequiredLength = 8;
}).AddRoles<ApplicationRole>()
.AddEntityFrameworkStores<MyDbContext>()
.AddUserManager<ApplicationUserManager>()
.AddDefaultTokenProviders();

// Set expiration time for confirmation links 
services.Configure<DataProtectionTokenProviderOptions>(options =>
{
    options.TokenLifespan = TimeSpan.FromMinutes(confirmationLinksExpirationInMinutes);
});

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); 
services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

})
.AddJwtBearer(cfg =>
{
    cfg.RequireHttpsMetadata = false;
    cfg.SaveToken = true;
    cfg.TokenValidationParameters = new TokenValidationParameters
    {
        ValidIssuer = Configuration["JwtBearerSettings:Issuer"],
        ValidAudience = Configuration["JwtBearerSettings:Issuer"],
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtBearerSettings:SecurityKey"])),
        ClockSkew = TimeSpan.Zero 
    };
});

Update #2

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Autofac" Version="4.9.4" />
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="3.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
  </ItemGroup>
  <ItemGroup>
    <Content Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Update="log4net.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
</Project>

I think that the autogenerated files come from AddDefaultIdentity .

When using AddDefaultUI(UIFramework.Bookstrap4) , ASP.NET Core automatically uses views for all of the identity views (I think there are 28 of them) but they are hidden from the solution. You can manually include and modify them by scaffolding identity . However, when you delete these views, they are not removed but rather autogenerated and hidden again.

I guess that the created CSS and JS files are autogenerated for these auto-generated views.

You can change you call to add identity to avoid this by using

services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
    options.SignIn.RequireConfirmedEmail = true;
    options.Password.RequireDigit = true;
    options.Password.RequireLowercase = true;
    options.Password.RequireNonAlphanumeric = true;
    options.Password.RequireUppercase = true;
    options.Password.RequiredLength = 8;
})
.AddEntityFrameworkStores<MyDbContext>()
.AddUserManager<ApplicationUserManager>()
.AddDefaultTokenProviders();

Depending on whether you are using .NET Core 2.2 or .NET Core 3.1, you might need to add an additional NuGet package. (Not sure if my memory is correct: Microsoft.AspNetCore.Identity.EntityFrameworkCore v2.2.0 and v3.1.0 behave differently. You might need to add https://www.nuget.org/packages/Microsoft.AspNetCore.Identity/ when using v3.1.0)

That is the new method with Core 3.0+ All scripts, script libraries etc go in wwwroot folder

I used to keep all of these scripts in ~/Area/AreaName/scripts but core 3.0 will not read them out of that dir.

it is something to do with security and stopping people from being able to access those files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM