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.
Cheers,
Samitha
Blogs Tech stuff and many more...
Content Security Policy (CSP) can be used to protect any ASP.NET web application by identifying
Cheers,
Samitha
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
Following JavaScript code will append an external JavaScript file to the document body. This can be used as guide to load a JavaScript file on the fly.
<script type="text/javascript">
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.async = true;
newScript.src = 'https://somedomain.com/JsFileName.js';
document.getElementsByTagName("body")[0].appendChild(newScript);
</script>
cheers,
Samitha
This is a configuration file that tells Git what to ignore when committing changes to Git based repositories (the ones in GitHub).
The .gitignore file controls what files to ignore when committing changes to Git repositories. The good new is is there is a tool called gitignore.io. This tool will generate such files for us.
I like this as it allows to type programming languages/platforms and generates the file for us
Cheers,
Samitha
If you want to download a file in C # form a given url following code snippet can be used.
public static async Task Download(string remoteUri, string directory)
{
try
{
string filePath = Path.Combine(directory, Path.GetFileName(remoteUri));
var httpClient = new HttpClient();
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
using var stream = await httpClient.GetStreamAsync(remoteUri);
using var fileStream = new FileStream(filePath, FileMode.Create);
await stream.CopyToAsync(fileStream);
}
catch (Exception)
{
throw;
}
}
When calling the above method we can user as
Download("https://abc.com/Content/Images/imagename.jpg", Directory.GetCurrentDirectory() + "\\images\\").Wait();
Note that this code is compatible with .Net 6 and .Net 7.
cheers,
Samitha
If we want to determine the mime type of a given file, we can use the MimeTypeMap NuGet package. I found it very efficient and up to date with additions from many contributors.
Cheers,
Samitha
When integrating Vuie Js with .Net Core 6/7, I found this youtube video really helpful. As .Net core APi and Vue js run in its own port I had to first run the API in one browser instance and Vue js frontend in another instance (typically http://localhost:8080/)
Cheers,
Samitha