ok i have checked mapping its correct.
Also how to avoid this error by abp api "The data you have submitted has already changed by another user/client. Please discard the changes you've done and try from the beginning" Thanks
ya it worked thanks
when we say Busnessexception or friendly exception it results into status code 403 which is wrong code as user has permissions but contact cannot be added due to validation so we wanted to show a message with different status code than 403
Its 403 which comes when user does not have permission
Thanks for the links, we will try and implement please keep this open for next 3-4 days then if you don't hear from us you can close this ticket.
Any update on this we are awaiting this since long its hampering our development.
Error is gone as of now, we used last code copy which was deployed on UAT and modified APi.HostModule in API host project. but not sure what went wrong and how error is gone.
you can uncomment the commented code for background jobs to reproduce.
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.AspNetCore.Authentication.Google; using Microsoft.AspNetCore.Authentication.MicrosoftAccount; using Microsoft.AspNetCore.Authentication.Twitter; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Extensions.DependencyInjection; using OpenIddict.Validation.AspNetCore; using OpenIddict.Server.AspNetCore; using Wbi.EntityFrameworkCore; using Wbi.MultiTenancy; using Microsoft.OpenApi.Models; using Volo.Abp; using Volo.Abp.Account.Web; using Volo.Abp.Account.Public.Web; using Volo.Abp.Account.Public.Web.Impersonation; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Autofac; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.VirtualFileSystem; using Volo.Abp.Account; using Volo.Abp.Account.Public.Web.ExternalProviders; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Microsoft.AspNetCore.Hosting; using Wbi.HealthChecks; using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonX; using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonX.Bundling; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.Identity; using Volo.Abp.LeptonX.Shared; using Volo.Abp.Swashbuckle; using Volo.Saas.Host; using Volo.Abp.OpenIddict; using Microsoft.IdentityModel.Tokens; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Http; using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring.FileSystem; using Serilog; using Volo.Abp.Auditing; using Volo.Abp.BlobStoring.Database; using Volo.FileManagement; using ProjectModule; using Volo.Abp.BackgroundJobs; using Microsoft.EntityFrameworkCore; using MasterModule.LookUps; using MasterModule.Provinces; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.BackgroundWorkers; using Wbi.Services.BackGroundJobs;
namespace Wbi;
[DependsOn( typeof(WbiHttpApiModule), typeof(AbpAutofacModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(WbiApplicationModule), typeof(WbiEntityFrameworkCoreModule), typeof(AbpAspNetCoreMvcUiLeptonXThemeModule), typeof(AbpAccountPublicWebImpersonationModule), typeof(AbpAccountPublicWebOpenIddictModule), typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreSerilogModule), typeof(AbpBlobStoringFileSystemModule) )] public class WbiHttpApiHostModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) {
#if RELEASE //test commit. //these are new changes made to deploy this app to IIS, to get rid of development certificates. PreConfigure<AbpOpenIddictAspNetCoreOptions>(options => { options.AddDevelopmentEncryptionAndSigningCertificate = false; });
//if we need to run this app on azure or load balancer, the signing keys wil not work, we may have to use x509 certificate
PreConfigure<OpenIddictServerBuilder>(builder =>
{
// builder.AddEncryptionKey(new SymmetricSecurityKey
// (Convert.FromBase64String("DRjd/GnduI3Efzen9V9BvbNUfc/VKgXltV7Kbk9sMkY=")));
//Set options here...
builder.AddEphemeralEncryptionKey()
.AddEphemeralSigningKey();
});
#endif
PreConfigure<OpenIddictBuilder>(builder =>
{
builder.AddValidation(options =>
{
options.AddAudiences("Wbi");
options.UseLocalServer();
options.UseAspNetCore();
});
});
PreConfigure<OpenIddictServerBuilder>(builder =>
{
builder
.SetAccessTokenLifetime(TimeSpan.FromHours(1))
.SetIdentityTokenLifetime(TimeSpan.FromHours(1));
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
Configure<AbpBlobStoringOptions>(options =>
{
options.Containers.Configure<DocumentContainer>(container =>
{
container.UseFileSystem(fileSystem =>
{
fileSystem.BasePath = configuration["DocumentPaths:UploadDocuments"];
//fileSystem.BasePath = "C:\\Blobdocs";
});
});
});
//Configure<AbpBackgroundJobWorkerOptions>(options =>
//{
// options.DefaultTimeout = 864000; //10 days (as seconds)
//});
Configure<AbpBackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = true; //Disables job execution
});
//Configure<AbpBlobStoringOptions>(options =>
// {
// options.Containers.Configure("account-profile-pictures", container =>
// {
// container.UseFileSystem(fileSystem =>
// {
// fileSystem.BasePath = configuration["DocumentPaths:UploadDocuments"];
// //fileSystem.BasePath = "C:\\Blobdocs";
// });
// });
// });
//Configure<AbpBlobStoringOptions>(options =>
//{
// options.Containers.Configure("documents", container =>
// {
// container.UseFileSystem(fileSystem =>
// {
// fileSystem.BasePath = configuration["DocumentPaths:UploadDocuments"];
// //fileSystem.BasePath = "C:\\Blobdocs";
// });
// });
//});
context.Services.ConfigureApplicationCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromHours(1); // Set the expiration time to 5 minutes
options.SlidingExpiration = false;
});
Configure<AbpAuditingOptions>(options =>
{
options.EntityHistorySelectors.AddAllEntities();
});
if (!Convert.ToBoolean(configuration["App:DisablePII"]))
{
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
}
if (!Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]))
{
Configure<OpenIddictServerAspNetCoreOptions>(options =>
{
options.DisableTransportSecurityRequirement = true;
});
}
if (!Convert.ToBoolean(configuration["App:DisablePII"]))
{
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
}
if (!Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]))
{
Configure<OpenIddictServerAspNetCoreOptions>(options =>
{
options.DisableTransportSecurityRequirement = true;
});
}
ConfigureAuthentication(context);
ConfigureUrls(configuration);
ConfigureBundles();
ConfigureConventionalControllers();
ConfigureImpersonation(context, configuration);
ConfigureSwagger(context, configuration);
ConfigureVirtualFileSystem(context);
ConfigureCors(context, configuration);
ConfigureExternalProviders(context);
ConfigureHealthChecks(context);
ConfigureTheme();
}
private void ConfigureTheme()
{
Configure<LeptonXThemeOptions>(options =>
{
options.DefaultStyle = LeptonXStyleNames.System;
});
}
private void ConfigureAuthentication(ServiceConfigurationContext context)
{
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
}
private void ConfigureHealthChecks(ServiceConfigurationContext context)
{
context.Services.AddWbiHealthChecks();
}
private void ConfigureUrls(IConfiguration configuration)
{
Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
options.Applications["Angular"].RootUrl = configuration["App:AngularUrl"];
options.Applications["Angular"].Urls[AccountUrlNames.PasswordReset] = "account/reset-password";
options.Applications["Angular"].Urls[AccountUrlNames.EmailConfirmation] = "account/email-confirmation";
options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"].Split(','));
});
}
private void ConfigureBundles()
{
Configure<AbpBundlingOptions>(options =>
{
options.StyleBundles.Configure(
LeptonXThemeBundles.Styles.Global,
bundle =>
{
bundle.AddFiles("/global-styles.css");
}
);
});
}
private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
if (hostingEnvironment.IsDevelopment())
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<WbiDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Wbi.Domain.Shared"));
options.FileSets.ReplaceEmbeddedByPhysical<WbiDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Wbi.Domain"));
options.FileSets.ReplaceEmbeddedByPhysical<WbiApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Wbi.Application.Contracts"));
options.FileSets.ReplaceEmbeddedByPhysical<WbiApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Wbi.Application"));
});
}
}
private void ConfigureConventionalControllers()
{
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(WbiApplicationModule).Assembly);
});
}
private static void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"Wbi", "Wbi API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Wbi API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
}
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder
.WithOrigins(
configuration["App:CorsOrigins"]
.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(o => o.Trim().RemovePostFix("/"))
.ToArray()
)
.WithAbpExposedHeaders()
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
}
private void ConfigureExternalProviders(ServiceConfigurationContext context)
{
context.Services.AddAuthentication()
.AddGoogle(GoogleDefaults.AuthenticationScheme, _ => { })
.WithDynamicOptions<GoogleOptions, GoogleHandler>(
GoogleDefaults.AuthenticationScheme,
options =>
{
options.WithProperty(x => x.ClientId);
options.WithProperty(x => x.ClientSecret, isSecret: true);
}
).AddCookie(options =>
{
// add an instance of the patched manager to the options:
options.CookieManager = new ChunkingCookieManager();
options.Cookie.HttpOnly = true;
options.Cookie.SameSite = SameSiteMode.None;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
})
.AddMicrosoftAccount(MicrosoftAccountDefaults.AuthenticationScheme, options =>
{
//Personal Microsoft accounts as an example.
options.AuthorizationEndpoint = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize";
options.TokenEndpoint = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token";
})
.WithDynamicOptions<MicrosoftAccountOptions, MicrosoftAccountHandler>(
MicrosoftAccountDefaults.AuthenticationScheme,
options =>
{
options.WithProperty(x => x.ClientId);
options.WithProperty(x => x.ClientSecret, isSecret: true);
}
)
.AddTwitter(TwitterDefaults.AuthenticationScheme, options => options.RetrieveUserDetails = true)
.WithDynamicOptions<TwitterOptions, TwitterHandler>(
TwitterDefaults.AuthenticationScheme,
options =>
{
options.WithProperty(x => x.ConsumerKey);
options.WithProperty(x => x.ConsumerSecret, isSecret: true);
}
);
}
private void ConfigureImpersonation(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.Configure<AbpAccountOptions>(options =>
{
options.TenantAdminUserName = "admin";
options.ImpersonationTenantPermission = SaasHostPermissions.Tenants.Impersonation;
options.ImpersonationUserPermission = IdentityPermissions.Users.Impersonation;
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//below cofigures auto trigger to background job
//context.ServiceProvider
//.GetRequiredService<IBackgroundWorkerManager>()
//.AddAsync(
// context
// .ServiceProvider
// .GetRequiredService<SecurityRequirement_Job>()
//);
// end of job
app.UseAbpRequestLocalization();
if (!env.IsDevelopment())
{
app.UseErrorPage();
}
app.UseAbpSecurityHeaders();
app.UseStaticFiles();
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseAbpOpenIddictValidation();
if (MultiTenancyConsts.IsEnabled)
{
app.UseMultiTenancy();
}
app.UseUnitOfWork();
app.UseAuthorization();
app.UseSwagger();
app.UseAbpSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Wbi API");
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
});
app.UseAuditing();
app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints();
}
}
can you please share documentation link,meanwhile i provide you the error message in angular app we are encountering
Thanks