Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Emre Kızıldaş emrekizildas

🎯
Focusing
View GitHub Profile
View firstusage.cs
public class FirstUsageModel : PageModel
{
private readonly IHttpClientFactory _clientFactory;
public IEnumerable<User> Users { get; private set; }
public bool GetUsersError { get; private set; }
public BasicUsageModel(IHttpClientFactory clientFactory)
{
View startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
View index.cshtml
@using CSPExample.Helper
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="#" id="click">building Web apps with ASP.NET Core</a>.</p>
</div>
View nonce.cs
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace CSPExample.Helper
{
public static class NonceHelper
{
public static HtmlString Nonce(this IHtmlHelper helper)
{
string nonceValue = helper.ViewContext.HttpContext.Items["ScriptNonce"].ToString();
View startup.cs
app.Use((context, next) =>
{
var rng = new RNGCryptoServiceProvider();
var nonceBytes = new byte[32];
rng.GetBytes(nonceBytes);
var nonce = Convert.ToBase64String(nonceBytes);
context.Items.Add("ScriptNonce", nonce);
context.Response.Headers.Add("Content-Security-Policy",
new[] { string.Format("script-src 'self' 'nonce-{0}'", nonce) });
return next();
View HomeController.cs
[ActionLogger]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
View ActionLog.cs
public override void OnActionExecuted(ActionExecutedContext context)
{
System.Net.IPAddress ipAddress = context.HttpContext.Connection.RemoteIpAddress;
string controllerName = ((ControllerActionDescriptor)context.ActionDescriptor).ControllerName;
string actionName = ((ControllerActionDescriptor)context.ActionDescriptor).ActionName;
if (context.Exception == null)
{
Log
.ForContext("IPAddress", ipAddress)
View startup.cs
public Startup(IConfiguration configuration, IHostingEnvironment environment)
{
Configuration = configuration;
Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", configuration.GetSection("AWS:AccessKey").Value);
Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", configuration.GetSection("AWS:SecretKey").Value);
Environment.SetEnvironmentVariable("AWS_REGION", configuration.GetSection("AWS:Region").Value);
Log.Logger = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(configuration.GetSection("AWS:ElasticUrl").Value))
View HomeController.cs
using System;
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Minio;
using Minio.DataModel;
using Minio.Exceptions;
View DownloadFile.cs
public async Task<FileResult> DownloadFile(string fileName)
{
//MinIO Bağlantısı
string endPoint = _config["Minio:Endpoint"];
string accessKey = _config["Minio:Accesskey"];
string secretKey = _config["Minio:SecretKey"];
MinioClient minioClient = new MinioClient(endPoint, accessKey, secretKey);
string bucketName = "medium";
You can’t perform that action at this time.