Contents tagged with .Net Core

  • How to add Database context to Filter in .Net Core 2.0

    Hello everybody,

    today I want to write a short description on how to add database context to IAuthorizationFilter.

    Imagine that you have following filter:

    public class HasApprovedFilter : Attribute, IAuthorizationFilter

    {

        private SomeDbContext _context;

        public HasApprovedFilter(SomeDbContext context)

        {

            this._context = context;

        }

        public void OnAuthorization(AuthorizationFilterContext context)

        {

            var user = context.HttpContext.User;

            if (!user.Identity.IsAuthenticated)

            {

                return;

            }

            var userAdd = _context.;

            //var um = context.HttpContext.RequestServices.GetService();

        }

    } … more

  • Types of fliters in .Net Core

    Hello everybody,

    today I want to make a short document about filters in .Net Core.

    There are by default four types of filters:

    Filters that implement IAuthorizationFilter which allow us to implement OnAuthorization method which allow us to add custom security logic.

    Filters that implement IActionFilter has two methods: OnActionExecuting, OnActionExecuted. Those two methods executed before and after action executing.

    Filters that implement IExceptionFilter has method OnException, which allows to handle exceptions.

    Filters that implement IResultFilter has two methods: OnResultExecuting, OnResultExecuted.

    Filters can be applied at controller or at action level. That gives following … more

  • .Net core tag helpers

    Hello everybody,

    today I want to describe some .Net core tag helpers that you can use in order to create your web pages. There are plenty of already implemented tag helpers that can simplify your life as a developer.

    Here is the list of already made:

    Anchor

    Cache

    Distributed

    Environment

    Form

    FormAction

    Img

    Input

    Label

    Link

    Option

    Script

    Select

    TextArea

    ValidationMessage

    ValidationSummary

    It is not a complete list, but I suppose those 16 elements help you to grasp how wide it's functionality.

    Anchor Tag Helper

    Consider following declaration:

    <a asp-controller='Presenter' asp-action='Presentation' asp-route-id=@Model.PresenterID>Presenter ID: @Model.PresenterID</a> … more

  • How to use package manager console for creating migrations

    Hello everybody,

    today I want to describe some basic steps that you can use in order to create and apply migrations to your code.

    So, let's start. 

    Imagine that in your .Net Core project you made some changes and would like them to be created in a form of C# code migration. How to do this in package manager console? Below are steps that I've applied:

    1. add-migration "identity"

    2. update-database

    Enjoy with results. The first command will create for your C# code that will describe which tables need to be created. Second command will execute that C# code and will create on your db them. 

    more

  • Different types of views

    Hello everybody,

    today I want to write few words about different kinds of Views in .Net core.

    So, if you decide somehow to create new view you can see something like this:

    and now question. What is the difference between MVC View Page, MVC View Layout Page, MVC View Start Page and MVC View Imports page?

    So, if to draw the lines then following can be said. 

    MVC View Page is fitting for displaying different models.

    MVC View Layout Page is inteded as View that has @RenderBody() statement. RenderBody will be placeholder where MVC View Page will be rendered. 

    MVC View Start Page is used as mediator between MVC View Page and MVC View Layout page.

    The last puzzling view is MVC View … more