نظرات مطالب
اعتبارسنجی مبتنی بر JWT در ASP.NET Core 2.0 بدون استفاده از سیستم Identity
سلام. وقت بخیر. من سیاست دسترسی پویا رو به jwt اضافه کردم. کلیه Claimها رو  به accesstoken اضافه میکنم و درست هم عملیات دسترسی چک میشود.
{"jti":"26bdfd20-104f-45d4-a4e1-111044808041",
"iss":"http://localhost:5000/",
"iat":1531729854,
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier":"1",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name":"Vahid",
"DisplayName":"وحید",
"http://schemas.microsoft.com/ws/2008/06/identity/claims/serialnumber":"046fb152a7474043952475cfa952cdc9",
"http://schemas.microsoft.com/ws/2008/06/identity/claims/userdata":"1",
"DynamicPermission":[":MyProtectedApi2:Get",
":MyProtectedEditorsApi:Get",
":MyProtectedApi3:Get",
":MyProtectedApi4:Get"],
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role":["Admin",
"Editor",
"User"],
"nbf":1531729855,
"exp":1531729975,
"aud":"Any"}
 فقط این Claimها که در توکن اضافه میشود در سمت سرور از روی توکن ارسالی کاربر چک میشود؟
 public bool CanUserAccess(ClaimsPrincipal user, string area, string controller, string action)
        {
            var currentClaimValue = $"{area}:{controller}:{action}";
            var securedControllerActions = _mvcActionsDiscoveryService.GetAllSecuredControllerActionsWithPolicy(ConstantPolicies.DynamicPermission);
            if (!securedControllerActions.SelectMany(x => x.MvcActions).Any(x => x.ActionId == currentClaimValue))
            {
                throw new KeyNotFoundException($@"The `secured` area={area}/controller={controller}/action={action} with `ConstantPolicies.DynamicPermission` policy not found. Please check you have entered the area/controller/action names correctly and also it's decorated with the correct security policy.");
            }

            if (!user.Identity.IsAuthenticated)
            {
                return false;
            }

            if (user.IsInRole("Admin"))
            {
                // Admin users have access to all of the pages.
                return true;
            }

            // Check for dynamic permissions
            // A user gets its permissions claims from the `ApplicationClaimsPrincipalFactory` class automatically and it includes the role claims too.


            //for check user has claim for access to action
            return user.HasClaim(claim => claim.Type == ConstantPolicies.DynamicPermissionClaimType &&
                                          claim.Value == currentClaimValue);
        }
امکان دستکاری توسط کاربر وجود ندارد؟ اگر اینطور است چطور این دسترسی‌ها رو در سمت سرور بعد از login در حافظه سرور ذخیره کنیم برای دفعات بعد؟
اشتراک‌ها
دریافت به روز رسانی کتاب The Little ASP.NET Core
  • Removed the AJAX pattern to focus even more on MVC best practices
  • Removed Facebook login to reduce problems for first-time readers
  • Updated the Docker deployment instructions to reflect the latest practices
  • A new jacket design
  • Many typo fixes and small suggestions! 
دریافت به روز رسانی کتاب The Little ASP.NET Core
نظرات مطالب
یکپارچه سازی Angular CLI و ASP.NET Core در VS 2017
یک نکته‌ی تکمیلی
Microsoft.DotNet.Web.Spa.ProjectTemplates  در آخرین نگارش آن، پشتیبانی از Angular CLI را هم افزوده‌است. برای کار با آن و ایجاد یک پروژه‌ی جدید بر مبنای آن دستورات ذیل را صادر کنید:
> dotnet new --install Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-preview1-final
> dotnet new angular
سپس اگر به فایل‌های Startup.cs و csproj آن دقت کنید، نحوه‌ی استفاده‌ی از بسته‌ی نیوگت Microsoft.AspNetCore.SpaServices.Extensions را جهت معرفی مسیر ClientApp/dist و راه اندازی خودکار UseAngularCliServer مشاهده خواهید کرد.

توضیحات بیشتر:
About The Updated SPA Templates From ASP.NET Core 
Migrating from the old ASP.NET Core Angular Spa template to the newer one  
فایل‌های پروژه‌ها
PdfRpt-2.8.7z
- Added ShouldSkipRow, ShouldSkipFooter & ShouldSkipHeader events. See Events/EventsPdfReport.cs sample for more info.
- Updated the project to use iTextSharp.5.5.5.
- Improved: Font styles (size, color etc.) are not applied if HTML fragment is rendered and does not have an explicit font-family style. patch #17253.
- Improved: Properly aligning the aggregate value, based on the column information. #2395
نظرات مطالب
Blazor 5x - قسمت 19 - کار با فرم‌ها - بخش 7 - نکات ویژه‌ی کار با EF-Core در برنامه‌های Blazor Server
جهت ثبت و دریافت داده‌ها من از MediateR استفاده کردم.
در مرحله اول context را مطابق الوی گفته شده ایجاد کردم:
services.AddDbContextFactory<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
services.AddScoped<IunitOfWork>(serviceProvider =>
        serviceProvider.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContext());
سپس با توجه به اینکه سرویس‌ها و IunitOfwork هم داخل هندلرها تعریف می‌شوند تنها اینترفیس Idisposable به  IunitOfwork   نسبت داده شده است:
public interface IUnitOfWork : IDisposable
و سپس 
@inherits  OwningComponentBase<IMediator>

تا به حال مشکلی در اجرا دیده نشد تا اینکه در حالت OnParameterAsync که دو مرتبه پشت سر هم اجرا میشود با خطاهای زیر روبرو شد:
 A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext.
 For more information on how to avoid threading issues with DbContext

 System.ObjectDisposedException: Cannot access a disposed object.
      Object name: 'IServiceProvider'.
در صورتی که اگر با یک فلگ کنترل شود که در مرتبه‌های بعدی اجرا نشود مشکلی نیست.
در این حالت چند سوال مطرح میباشد:
1- آیا استفاده از MediateR به این شکل صحیح است؟ و اینکه استفاده از OwningComponentBase برای آن تاثیری دارد یا خیر اینکه مستقیم هم Inject شود کفایت میکند.
2- به جهت اینکه Onparameter دوبار صدا زده میشود. نحوه واکشی دیتا در این حالت چگونه است؟