HTTP 2 در نگارش بعدی IE
NetEscapades.AspNetCore.SecurityHeaders
A small package to allow adding security headers to ASP.NET Core websites. example :
public void Configure(IApplicationBuilder app) { var policyCollection = new HeaderPolicyCollection() .AddFrameOptionsDeny() .AddXssProtectionBlock() .AddContentTypeOptionsNoSniff() .AddStrictTransportSecurityMaxAgeIncludeSubDomains(maxAgeInSeconds: 60 * 60 * 24 * 365) // maxage = one year in seconds .AddReferrerPolicyStrictOriginWhenCrossOrigin() .RemoveServerHeader() .AddContentSecurityPolicy(builder => { builder.AddObjectSrc().None(); builder.AddFormAction().Self(); builder.AddFrameAncestors().None(); }) .AddCustomHeader("X-My-Test-Header", "Header value"); app.UseSecurityHeaders(policyCollection); // other middleware e.g. static files, MVC etc }
SQL Antipattern #2
/// Example: "00001.00042.00005".
/// Example: "00001.00042.00006".
public class OrganizationalUnit : TrackableEntity<User>, IHasRowVersion, IPassivable { #region Constants /// <summary> /// Maximum depth of an UO hierarchy. /// </summary> public const int MaxDepth = 16; /// <summary> /// Length of a code unit between dots. /// </summary> public const int PathUnitLength = 5; /// <summary> /// Maximum length of the <see cref="Path"/> property. /// </summary> public const int MaxPathLength = MaxDepth * (PathUnitLength + 1) - 1; public const char HierarchicalDisplayNameSeperator = '»'; #endregion #region Properties public string Name { get; set; } public string NormalizedName { get; set; } public string HierarchicalDisplayName { get; set; } /// <summary> /// Hierarchical Path of this organization unit. /// Example: "00001.00042.00005". /// It's changeable if OU hierarch is changed. /// </summary> public string Path { get; set; } public bool IsActive { get; set; } = true; public byte[] RowVersion { get; set; } #endregion #region Navigation Properties public OrganizationalUnit Parent { get; set; } public long? ParentId { get; set; } public ICollection<OrganizationalUnit> Children { get; set; } = new HashSet<OrganizationalUnit>(); public ICollection<UserOrganizationalUnit> UserOrganizationalUnits { get; set; } = new HashSet<UserOrganizationalUnit>(); #endregion #region Public Methods /// <summary> /// Creates path for given numbers. /// Example: if numbers are 4,2 then returns "00004.00002"; /// </summary> /// <param name="numbers">Numbers</param> public static string CreatePath(params int[] numbers) { if (numbers.IsNullOrEmpty()) { return null; } return numbers.Select(number => number.ToString(new string('0', PathUnitLength))).JoinAsString("."); } /// <summary> /// Appends a child path to a parent path. /// Example: if parentPath = "00001", childPath = "00042" then returns "00001.00042". /// </summary> /// <param name="parentPath">Parent path. Can be null or empty if parent is a root.</param> /// <param name="childPath">Child path.</param> public static string AppendPath(string parentPath, string childPath) { if (childPath.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(childPath), "childPath can not be null or empty."); } if (parentPath.IsNullOrEmpty()) { return childPath; } return parentPath + "." + childPath; } /// <summary> /// Gets relative path to the parent. /// Example: if path = "00019.00055.00001" and parentPath = "00019" then returns "00055.00001". /// </summary> /// <param name="path">The path.</param> /// <param name="parentPath">The parent path.</param> public static string GetRelativePath(string path, string parentPath) { if (path.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(path), "Path can not be null or empty."); } if (parentPath.IsNullOrEmpty()) { return path; } if (path.Length == parentPath.Length) { return null; } return path.Substring(parentPath.Length + 1); } /// <summary> /// Calculates next path for given path. /// Example: if code = "00019.00055.00001" returns "00019.00055.00002". /// </summary> /// <param name="path">The path.</param> public static string CalculateNextPath(string path) { if (path.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(path), "Path can not be null or empty."); } var parentPath = GetParentPath(path); var lastUnitPath = GetLastUnitPath(path); return AppendPath(parentPath, CreatePath(Convert.ToInt32(lastUnitPath) + 1)); } /// <summary> /// Gets the last unit path. /// Example: if path = "00019.00055.00001" returns "00001". /// </summary> /// <param name="path">The path.</param> public static string GetLastUnitPath(string path) { if (path.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(path), "Path can not be null or empty."); } var splittedPath = path.Split('.'); return splittedPath[splittedPath.Length - 1]; } /// <summary> /// Gets parent path. /// Example: if path = "00019.00055.00001" returns "00019.00055". /// </summary> /// <param name="path">The path.</param> public static string GetParentPath(string path) { if (path.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(path), "Path can not be null or empty."); } var splittedPath = path.Split('.'); if (splittedPath.Length == 1) { return null; } return splittedPath.Take(splittedPath.Length - 1).JoinAsString("."); } #endregion }
البته یک ویو نمایشی برای حالت درختی هم بهتر است داشته باشید.
یکسری متد DomainService
public virtual async Task<string> GetNextChildPathAsync(long? parentId) { var lastChild = await GetLastChildOrNullAsync(parentId).ConfigureAwait(false); if (lastChild == null) { var parentPath = parentId != null ? await GetPathAsync(parentId.Value).ConfigureAwait(false) : null; return OrganizationalUnit.AppendPath(parentPath, OrganizationalUnit.CreatePath(1)); } return OrganizationalUnit.CalculateNextPath(lastChild.Path); } public async Task<string> GetNextChildHierarchicalDisplayNameAsync(string name, long? parentId) { var parent = parentId != null ? await _organizationalUnits.SingleOrDefaultAsync(a => a.Id == parentId.Value).ConfigureAwait(false) : null; return parent == null ? name : $"{parent.HierarchicalDisplayName} {OrganizationalUnit.HierarchicalDisplayNameSeperator} {name}"; } public virtual async Task<OrganizationalUnit> GetLastChildOrNullAsync(long? parentId) { return await _organizationalUnits.OrderByDescending(c => c.Path) .FirstOrDefaultAsync(ou => ou.ParentId == parentId).ConfigureAwait(false); } public virtual async Task<string> GetPathAsync(long id) { Guard.ArgumentNotZero(id, nameof(id)); var organizationalUnit = await _organizationalUnits.SingleOrDefaultAsync(ou => ou.Id == id).ConfigureAwait(false); if (organizationalUnit == null) { throw new KeyNotFoundException(); } return organizationalUnit.Path; } public async Task<List<OrganizationalUnit>> FindChildrenAsync(long? parentId, bool recursive = false) { if (!recursive) { return await _organizationalUnits.Where(ou => ou.ParentId == parentId).ToListAsync().ConfigureAwait(false); } if (!parentId.HasValue) { return await _organizationalUnits.ToListAsync().ConfigureAwait(false); } var path = await GetPathAsync(parentId.Value).ConfigureAwait(false); return await _organizationalUnits.Where( ou => ou.Path.StartsWith(path) && ou.Id != parentId.Value).ToListAsync().ConfigureAwait(false); } public virtual async Task MoveAsync(long id, long? parentId) { Guard.ArgumentNotZero(id, nameof(id)); var organizationalUnit = await _organizationalUnits.SingleOrDefaultAsync(ou => ou.Id == id).ConfigureAwait(false); if (organizationalUnit == null || organizationalUnit.ParentId == parentId) { return; } //Should find children before Path change var children = await FindChildrenAsync(id, true).ConfigureAwait(false); //Store old Path of OU var oldPath = organizationalUnit.Path; //Move OU organizationalUnit.Path = await GetNextChildPathAsync(parentId).ConfigureAwait(false); organizationalUnit.ParentId = parentId; //Update Children Paths foreach (var child in children) { child.Path = OrganizationalUnit.AppendPath(organizationalUnit.Path, OrganizationalUnit.GetRelativePath(child.Path, oldPath)); } }
EF Code First #12
CreateDatabase is not supported by the provider.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.ProviderIncompatibleException: CreateDatabase is not supported by the provider
بستن یک بازهی IP در IIS 6
در IIS6 باید به خواص وب سایت و برگهی Directory security آن مراجعه کرد. سپس در این قسمت، در حین افزودن IP مد نظر، باید گزینهی Group of computers را انتخاب نمود.
در اینجا برای مثال برای بستن IPهایی که با 194 شروع میشوند، باید 194.0.0.0 را وارد کرد و در این حالت subnet mask را نیز باید 255.0.0.0 انتخاب کرد. با این subnet mask خاص، اعلام میکنیم که فقط اولین قسمت IP وارد شده برای ما اهمیت دارد و سه قسمت بعدی خیر. به این ترتیب تمام IPهای شروع شده با 194 با هر سه جزء دیگر دلخواهی، بسته خواهند شد.
بستن یک بازهی IP در IISهای 7 به بعد
در IISهای 7 به بعد نیاز است مراحل زیر را طی کرده و نقش «IP and Domain Restrictions » را نصب کنید.
Administrative Tools -> Server Manager -> expand Roles -> Web Server (IIS) -> Role Services -> Add Role Services -> select IP and Domain Restrictions
<system.webServer> <security> <ipSecurity> <add ipAddress="192.168.100.1" /> <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" /> </ipSecurity> </security> </system.webServer>
IIS 7 -> root server -> Feature Delegation -> IP and Domain Restrictions -> Change the delegation to Read/Write
Learn Blazor WebAssembly and Web API on .NET 6 by building a shopping cart application using C#. This course also provides a guide on how to integrate a payment gateway into your Blazor WebAssembly component, so that a user is able to pay for products through your application using a debit or credit card or PayPal account.
⭐️ Course Contents ⭐️
⌨️ (0:00:00) Introduction
⌨️ (0:00:51) Create the Database using EF Core Code First Database Migrations
⌨️ (0:26:05) Retrieve Product Data from Database (Web API component)
⌨️ (0:30:17) Create Classes for Data Transfer Objects (DTOs)
⌨️ (0:36:22) Create ProductRepository Class (Repository Design Pattern)
⌨️ (0:43:05) Create ProductController Class
⌨️ (0:51:08) Create DtoConversion Class (DTO Conversion Extension methods)
⌨️ (0:57:45) Display Product Data to User (Blazor WebAssembly Component)
⌨️ (1:39:59) Display Data for Specific Product to User (Web API and Blazor)
⌨️ (2:06:07) Add Product to Shopping Cart (Web API and Blazor)
⌨️ (2:52:40) Remove Product from Shopping Cart (Web API and Blazor)
⌨️ (3:14:03) Update the Quantity of Products in the Shopping Cart (Web API, Blazor, Blazor JavaScript Interoperability)
⌨️ (3:44:01) Update the Header Menu in Response to a Change to the State of the Shopping Cart (Creating Custom Events in Blazor)
⌨️ (4:04:48) Integration of PayPal Payment Gateway into Blazor Component
⌨️ (4:36:03) Dynamically Populate the Side-Bar Menu (Web API and Blazor)
⌨️ (5:05:44) Optimise Code for Performance (Web API and Blazor)
⌨️ (5:08:26) Use Include Extension Method in LINQ Query (Web API)
⌨️ (5:14:00) User Local Storage Functionality (Blazor)
⌨️ (5:35:42) Outro