adsense

Saturday, April 20, 2024

ASP.NET Web Applications with Content Security Policy


 Content Security Policy (CSP) can be used to protect any ASP.NET web application by identifying  

  • Cross-site Scripting (XSS) attacks
  • SQL or data injection attacks.
We can use the web.config to configure CSP and this article explains various directives used for CSP and use of it.

Cheers,

Samitha

Monday, April 8, 2024

.Net core 6 db migration error

 I got following error when trying to run the migrations on a .NET Core 6 Web API.

Unable to create an object of type 'MyDBContext'

After tarting out different approaches following  changes made migrations work.


1. MyDbContext 

  

 public class MyDbContext : DbContext, IMyDbContext

    {

        public MyDbContext()

        {

            

        }

        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)

        {

            

       

        protected override void OnConfiguring(DbContextOptionsBuilder

 optionsBuilder)

        {

            optionsBuilder.UseSqlServer("Data Source=localhost;Initial Catalog = Library;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True");

        }

//...more code


}

2. Program.cs

builder.Services.ConfigureLoggerService(); 

//more options

options.UseSqlServer(builder.Configuration.GetConnectionString

("DefaultConnection")));


Cheers,

Samitha