All Projects → unosquare → swan-aspnetcore

unosquare / swan-aspnetcore

Licence: MIT license
SWAN ASP.NET Core

Programming Languages

C#
18002 projects
HTML
75241 projects

Projects that are alternatives of or similar to swan-aspnetcore

Aspnetcore Practice
ASP.NET Core 專案練習集合,ASP.NET Core Practice Projects
Stars: ✭ 80 (+185.71%)
Mutual labels:  dotnetcore, aspnet-core
Architecture
.NET 6, ASP.NET Core 6, Entity Framework Core 6, C# 10, Angular 13, Clean Code, SOLID, DDD.
Stars: ✭ 2,285 (+8060.71%)
Mutual labels:  dotnetcore, aspnet-core
Cronscheduler.aspnetcore
Cron Scheduler for AspNetCore 2.x/3.x or DotNetCore 2.x/3.x Self-hosted
Stars: ✭ 100 (+257.14%)
Mutual labels:  dotnetcore, aspnet-core
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-7.14%)
Mutual labels:  dotnetcore, aspnet-core
Dasblog Core
The original DasBlog reimagined with ASP.NET Core
Stars: ✭ 252 (+800%)
Mutual labels:  dotnetcore, aspnet-core
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+200%)
Mutual labels:  dotnetcore, aspnet-core
Peachpie
PeachPie - the PHP compiler and runtime for .NET and .NET Core
Stars: ✭ 1,945 (+6846.43%)
Mutual labels:  dotnetcore, aspnet-core
Wopihost
ASP.NET Core MVC implementation of the WOPI protocol. Enables integration with WOPI clients such as Office Online Server.
Stars: ✭ 132 (+371.43%)
Mutual labels:  dotnetcore, aspnet-core
Identity.dapper
Identity package that uses Dapper instead EntityFramework for use with .NET Core
Stars: ✭ 234 (+735.71%)
Mutual labels:  dotnetcore, aspnet-core
Dotnetcore Entityframework Api
Building REST APIs using ASP.NET Core and Entity Framework Core
Stars: ✭ 212 (+657.14%)
Mutual labels:  dotnetcore, aspnet-core
ASPNETcoreAngularJWT
Angular in ASP.NET Core with JWT solution by systemjs
Stars: ✭ 48 (+71.43%)
Mutual labels:  dotnetcore, bearer-tokens
GatewayService
GatewayService (Ocelot).
Stars: ✭ 19 (-32.14%)
Mutual labels:  dotnetcore, aspnet-core
AspNetCoreAzureSearch
ASP.NET Core with Azure Cognitive Search
Stars: ✭ 12 (-57.14%)
Mutual labels:  dotnetcore, aspnet-core
Awesome Microservices Netcore
💎 A collection of awesome training series, articles, videos, books, courses, sample projects, and tools for Microservices in .NET Core
Stars: ✭ 865 (+2989.29%)
Mutual labels:  dotnetcore, aspnet-core
Huxley2
A cross-platform JSON proxy for the GB railway Live Departure Boards SOAP API
Stars: ✭ 22 (-21.43%)
Mutual labels:  dotnetcore, aspnet-core
Serenity
Business Apps Made Simple with Asp.Net Core MVC / TypeScript
Stars: ✭ 2,168 (+7642.86%)
Mutual labels:  dotnetcore, aspnet-core
ApiJwtWithTwoSts
Web API authorization, multi-IDP solutions in ASP.NET Core
Stars: ✭ 43 (+53.57%)
Mutual labels:  dotnetcore, aspnet-core
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+210.71%)
Mutual labels:  dotnetcore, aspnet-core
Abp.AspNetCoreRateLimit
An Abp module helps you control how often your service is used.
Stars: ✭ 19 (-32.14%)
Mutual labels:  dotnetcore
Cloud.BookList
使用52ABP 多租户(SaaS)模式下的书单管理功能,Angular + .net core 案例功能
Stars: ✭ 14 (-50%)
Mutual labels:  dotnetcore

Build status Buils status

Swan ASP.NET Core 3: Stuff We All Need

Please star this project if you find it useful!

**NOTE: This repository has been archived. **

A set of libraries to use with ASP.NET Core 3.0 applications. Also, includes a configure middleware and extension to setup your project. ASP.NET Core 3.0 came with a lot of changes, including authentication and authorization, here with Swan ASP.NET Core 3.0 is easy to configure and start working on your project.

NuGet Installation:

NuGet version

PM> Install-Package Unosquare.Swan.AspNetCore

Use Cases

Here we can find a very useful code to use in our project configuration. All of this you can use it in your Startup.cs file, see our Sample Project for more reference.

Using Bearer Token Authentication

The extension method AddBearerTokenAuthentication adds the services that are going to be used in your application. This method uses the Jwt schemes and adds a JwtBearer with the Token Validation Parameters that you configure. Jwt stands for JSON Web Tokens

The extension method UseBearerTokenAuthentication is important because it gives the application the requirements to use authentication and authorization with JWT.

With this configuration, you just need to add the data annotation [Authorize] to your API to say that the user needs to be authorized to access that part of your project.

This two are used together because you need to add the bearer token authentication to the services to use the bearer token authentication in your application. You just need to add in your ConfigureServices and your Configure.

    // This method gets called by the runtime. Use this method to add services to the container
    public void ConfigureServices(IServiceCollection services)
    {
        // Extension method to add Bearer authentication
        services.AddBearerTokenAuthentication(ValidationParameters);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // Use the bearer token provider and check Admin and Pass.word as valid credentials
        app.UseBearerTokenAuthentication(
            ValidationParameters,
            (services, username, password, grantType, clientId) =>
            {
                if (username != "Admin" || password != "Pass.word")
                    return Task.FromResult<ClaimsIdentity>(null);

                var claim = new ClaimsIdentity("Bearer");
                claim.AddClaim(new Claim(ClaimTypes.Name, username));

                return Task.FromResult(claim);
            }, (identity, obj) =>
            {
                // This action is optional
                obj["test"] = "OK";
                return Task.FromResult(obj);
            });
    }

Using EntityFrameworkLogger

The EntityFrameworkLogger represents a Logger based on Entity Framework and adds a Logging subsystem. It will help you log into your Database everything necessary to know what’s going on in your application. This logger is used in the ConfigureServices method of your Startup.cs file.

With this you just add your configuration section and then add in the entity framework, your database context and the models that you use for log entries into your database, then you just pass the application services.

    public void ConfigureServices(IServiceCollection services)
    {
	    // Inject your DbContext first.

    	    //  Add Entity Framework Logging Provider
	    services.AddLoggingEntityFramework<SampleDbContext, Models.LogEntry>();
    }

Using BusinessDbContext

The BusinessDbContext run business rules when you save changes to the database. It's helpful because if you want to modify an entity every time you save changes to the database, you can create a controller to do that. Your Db Context must inheritance from the BusinessDbContext in order to have this functionality and then you can add, remove and check for controllers using your context.

    public class SampleDbContext : BusinessDbContext
    {
        public SampleDbContext(DbContextOptions<SampleDbContext> options)
            : base(options)
        {
        }
    }

AuditTrail

Audit Trails is a business rule to save the changes to any operation performed in a record. In other words, capture what change between any data saving. This operation is important in many systems and you can accomplish with these extensions easily. The AuditTrailController can be attached to your BusinessDbContext and setup which Entities will be recorded in the three CRUD actions supported, create, update and delete.

    public class SampleDbContext : BusinessDbContext
    {
         public SampleDbContext(DbContextOptions<SampleDbContext> options, IHttpContextAccessor httpContextAccessor)
            : base(options)
        {
            var auditController = new AuditTrailController<SampleDbContext, AuditTrailEntry>(this,
                httpContextAccessor?.HttpContext?.User?.Identity?.Name);
            auditController.AddTypes(ActionFlags.Create, new[] {typeof(Product)});

            AddController(auditController);
        }

        public DbSet<AuditTrailEntry> AuditTrailEntries { get; set; }
    }

Additional Extension Methods

Use the following extension methods to extend the ApplicationBuilder with helpful handlers.

The JsonExceptionHandler

Adding this extension is a very good way to debug your application. When an error occurs, the exception handles the error and send a 500 Internal Server Error HTTP Response with a JSON object containing useful information as stacktrace and inner exceptions.

// Response an exception as JSON at error
app.UseJsonExceptionHandler();

The Fallback

Redirect any 404 request without extension to specific URL like your index.html page. This is helpful when you are using client-side routing (like Angular) and redirect any unknown URL to the javascript application.

// Redirect anything without extension to index.html
app.UseFallback();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].