asp.net

url.ToString() and url.OriginalString

var uri3 = new Uri("https://onet.pl/?param=value%20space%20in");
 
Assert.Equal("https://onet.pl/?param=value space in", uri3.ToString());
// true            
Assert.Equal("https://onet.pl/?param=value%20space%20in", uri3.OriginalString);
// true
Kategoria: 

Example

     var sssss = await _managerPlatformDataService.GetPlatformData();
 
            var acvite = sssss.Single(x => x.IsActive && x.Code == AMZEU.ToString()).Marketplaces;
 
            foreach (var Channel in partnerPlatformsResponse?.PartnerChannels)
            {
                var marketplaceCodes = Channel.PartnerMarketplaces.Select(m => m.CountryCode);
 
                var missingMarketplaceResponseDtos = acvite
                    .ExceptBy(marketplaceCodes, m => m.CountryCode)
                    .Select(m => new PDto(new PM
                    {
                        Marketplace = m,
                        PartnerChannelId = Channel.Id
                    })
                    { IsAvailable = false });
 
                Channel.PartnerMarketplaces = Channel.PartnerMarketplaces
                    .Concat(missingMarketplaceResponseDtos)
                    .OrderBy(x => _orderOfMarkets.IndexOf(x.CountryCode))
                    .ToList();
            }
Kategoria: 

AddClaimsPrincipalFactory

            services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
            {
                var allowed = options.User.AllowedUserNameCharacters + "ęóąśłżźćń";
                options.User.AllowedUserNameCharacters = allowed;
            }).AddEntityFrameworkStores<DomainModelContext>()
               .AddRoles<ApplicationRole>()
               .AddClaimsPrincipalFactory<ApplicationClaimsIdentityFactory>()
 
               .AddDefaultTokenProviders();

 public class ApplicationClaimsIdentityFactory : UserClaimsPrincipalFactory<ApplicationUser, ApplicationRole>
    {
        private readonly IHttpContextAccessor _httpContext;
 
        public ApplicationClaimsIdentityFactory(UserManager<ApplicationUser> userManager, RoleManager<ApplicationRole> roleManager, IOptions<IdentityOptions> options, IHttpContextAccessor httpContext) : base(userManager, roleManager, options)
        {
            _httpContext = httpContext;
        }
 
        public override async Task<System.Security.Claims.ClaimsPrincipal> CreateAsync(ApplicationUser user)
        {
            ClaimsPrincipal principal = await base.CreateAsync(user);
 
            ClaimsIdentity claimsIdentity = (ClaimsIdentity)principal.Identity;
 
 
            var ddd = claimsIdentity.Claims.Where(x => x.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/name");
 
            foreach (var dd in ddd) {
                claimsIdentity.RemoveClaim(dd);
            }
 
            //claimsIdentity.Claims.ToList().RemoveAt(30);
 
            //claimsIdentity.Claims.Where(x => x.Type == )
            //claimsIdentity.AddClaim(new Claim("Deleted", user.Deleted.ToString().ToLower()));
 
 
            //_httpContext.HttpContext.User = principal;
 
 
            return principal;
        }
    }
Kategoria: 

Two-Factor Asp.core

var authenticatorCode = command.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
var twoFactor = await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, authenticatorCode);

https://chsakell.com/2019/08/18/asp-net-core-identity-series-two-factor-...
https://stackoverflow.com/questions/41084411/whats-the-difference-betwee...
https://blog.elmah.io/how-to-implement-two-factor-authentication-with-as...

Kategoria: 

Asp.core no caching controller methods

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
Kategoria: 

File asp.core Api swagger client NSwag

https://stackoverflow.com/questions/43844261/what-is-the-correct-way-to-download-a-file-via-the-nswag-code-generator-angular

1. Microsoft.AspNetCore.StaticFiles // To determine MimeType
2. NSwag.Annotations 

services.AddSwaggerGen(options =>
{
    // Swagger Configurations
    options.MapType<FileContentResult>(() => new OpenApiSchema
    {
        Type = "file"
    });
});

[HttpGet("Get_File")]
[SwaggerOperation("Get_File", OperationId = "Get_File")]
[SwaggerResponse(200, type: typeof(FileContentResult))]
[ProducesResponseType(typeof(FileContentResult), 200)]
public IActionResult GetFile()
{
    var filePath = "D:\\11.pdf"; // get file full path based on file name
    if (!System.IO.File.Exists(filePath))
    {
        return BadRequest();
     }
 
     return File(System.IO.File.ReadAllBytesAsync(filePath).Result, "application/octet-stream", "11.pdf");
}
Kategoria: 

entity rollbacl

Remove-Migration -context ***omainMo***xt  -Force
Kategoria: 

Json.Newton Setting

$type as property with namespace

services.AddControllers().AddNewtonsoftJson(
           x => x.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All
);

Swagger Polymorphism

 services.AddSwaggerGen(c =>
            {
                //c.UseOneOfForPolymorphism();
                c.UseAllOfForInheritance();
                c.SelectDiscriminatorNameUsing(_ => "discriminator");
                //c.CustomSchemaIds(type => type.ToString());

Swagger own Schema Proccesor

app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "*****.**** API V1");
                //c.GeneratorSettings.SchemaProcessors.Add(new InheritanceSchemaProcessor());
            });
 
 
            // app.UseSwaggerUI(typeof(Startup).GetTypeInfo().Assembly, settings =>
            // {
            //     settings.GeneratorSettings.SchemaProcessors.Add(new InheritanceSchemaProcessor());
            // });
Kategoria: 

revert Migration dotnet EntityFramework

To revert the last applied migration you should (package manager console commands):

Revert migration from database: PM> Update-Database
Remove migration file from project (or it will be reapplied again on next step)
Update model snapshot: PM> Remove-Migration

Kategoria: 

Strony

Subskrybuj asp.net