Here I'm going to post whatever that is interesting for me. All things about programming using JavaScript and ASP.NET Core. And something else.

A blog about ASP.Net Core and JavaScript

Tagged with MVC

Couple a days ago I was looking for some information about image uploading from external URL in an ASP.NET Core application. I‘ve found a great post written by Igor Sikorsky (see Sources [1]) and another one, which was written by Andrew Lock (see Sources [2]) who used the same approach.

But in Igor’s post discussion, someone noticed improper using of HttpClient to retrieve the image from external URL. Few seconds googling helped to find another interesting post by Simon Timms [3] which shows how to use HttpClient correctly. He suggests declaring a static instance of HttpClient in the .NET Core application main class.

It is cool, but what if I do not want to use HttpClient as a property of the main app class. What if I want to get it from DI service?

If you are interested in this approach too, welcome to read more…

A while ago webpack 4 has been released. And it is really fast. It is not fast as daylight, but it is quicker than Gulp or Grunt.

Despite this, when you try to find some examples how to use it to deal with ASP.NET Core 2.x, you'll fail. Ok! You will not. At least, you have found this post ;).  But most examples on the Internet use webpack 2.x.

This guide shows results of my researching and experiments while building a very minimalistic ASP.NET Core 2.1 application with Visual Studio 2017. Here I will use tools and pipelines that are conventional among the front-end developers:

  • NPM package manager to manage Node.js packages and to run scripts.
  • Javascript ES6-module syntax in the JavaScript code.
  • SASS to process styles.
  • webpack 4 to bundle all things together.

So, let's start.

There are a lot of interesting articles, tutorials and blog posts which describe authorization with roles and policies. Simple googling will help you to find among them, for example:

  • Official ASP.NET Core documentation tutorial.
  • Temi Lajumoke’s article about using custom user roles for ASP.NET Core.
  • Juan Carlos Sanchez’s post.

But even after you'll read all of them, it's hard to get answers to the few questions:

  • How to seed initial records of the users and roles to the database?
  • How to restrict access to the page menu items for those users, who belongs only to special roles?
  • And how to assign the new user to the default role?