List of Posts under ASP.NET Core Seq 1

This is a list of of posts written under the category ASP.NET Core Seq 1. Scroll down to see all the posts. They have been ordered by the date of publish.
(Rev. 19-Mar-2024)

Categories | About |     |  

List of Posts

This is the complete list of categories of posts written under the category ASP.NET Core Seq 1. They have been ordered by the publish date, with the most recent first.

  1. Published: 29-Nov-2021
    Following are the minimal steps needed to run a hello world type of razor component that handles a click event. The component will have to be based on blazor because events have to be handled. The events are processed on the server side. If no events have to be handled, then these steps are not required - you should use render-mode=Static


  2. Published: 24-Nov-2021
    (LEVEL IS BEGINNERS) These are practice questions and exercises on Modularity in Razor Pages. Solve them and join our course for their solutions.


  3. Published: 23-Nov-2021
    Following are some of the reasons that you can consider when deciding on learning ASP.NET Core. I think .NET Core has a good future and in the coming days it is about to become the default web development technology. Write to us if you have something to add!


  4. Published: 09-Nov-2021
    (LEVEL IS BEGINNERS) These are practice questions and exercises on Basic database connectivity in Razor Pages. Solve them and join our course for their solutions.


  5. Published: 02-Nov-2021
    (LEVEL IS BEGINNERS) These are practice questions and exercises on Basic Event Handling in Razor Pages. Solve them and join our course for their solutions.


  6. Published: 02-Nov-2021
    (LEVEL IS BEGINNERS) Following is a collection of exercises and practice questions that help in cementing the concepts of asp.net core razor pages. Solve them and join our course for their solutions.


  7. Published: 01-Oct-2021
    A result set can be sorted in ascending as well as descending order. It is even possible to perform a chained sorting by using "ThenBy" and "ThenByDescending" methods. Finally we discuss whether "OrderBy" should be before or after "Where".


  8. Published: 01-Oct-2021
    EF Core translates your LINQ expressions into SQL language queries. However, sometimes it is easier, convenient and faster (as determined by testing) to run queries directly on a database. This tutorial explains how to run SELECT, UPDATE, INSERT, DELETE and execute Stored Procedures and obtain the resultset directly.


  9. Published: 01-Oct-2021
    This is an explanation of Where, Include and the ToList methods from a practical point of view. We have explained when to use which one and how to use. We have also explained how a SQL JOIN can be performed by using the "Include" function of EF Core.


  10. Published: 01-Oct-2021
    This is an explanation of SingleOrDefault, FirstOrDefault and Find methods from a practical point of view. We have explained when to use which one and how to use. We have also explained how Single is different from First, and how Single is different from SingleOrDefault, and also how First is different from FirstOrDefault.


  11. Published: 28-Sep-2021
    A file can be downloaded by returning a FileResult. This article explains how a FileResult is created. Finally, a walkthrough is given that shows a complete upload-download scenario.


  12. Published: 28-Sep-2021
    This is a quick and clean scheme for uploading files to a server. In the first part we demonstrate how to store them into a database table. And, in the second we have a word of caution about putting them into a database. A better strategy would, instead, be to store them on a disk, possibly on a separate partition, and a method for doing this is also explained in the end.


  13. Published: 23-Sep-2021
    Following is a brief scheme on signing out a logged-in user. A function for sign-out is written in the same file as for the login code. Then this function is called from the click of some anchor link and "SignOutAsync" called to kill the login cookie. Finally, a redirection is done to the login page.


  14. Published: 22-Sep-2021
    This is a snippet on showing "You are logged as ..." on every page that an authenticated and authorized user visits. The code can be inserted in a razor page or in a partial page.


  15. Published: 22-Sep-2021
    This article starts with an explanation of "SignIn", and then explains the various steps for a signin process. Finally, we discuss what is a returnUrl, and what is LocalRedirect, and when should it be used.


  16. Published: 22-Sep-2021
    This is an explanation of how an "Area" based ASP.NET Core project can be configured for role and policy based authorization. Authorization can be applied to the entire "Area" directory. We also explain how to specify the login and access denied pages.


  17. Published: 17-Sep-2021
    This is a brief explanation of how to specify single primary key on a model through attributes - but this approach fails when multiple columns are to be set as the primary key. We explain that such a composite primary key has to be set through the DbContext. Finally, we explain how to query a record on the basis of its primary key.


  18. Published: 16-Sep-2021
    SaveChanges can fail if a constraint fails, if a connection error occurs or if any generic error occurs. So it should always be wrapped in a try-catch handler to gracefully handle the DbUpdateException. But how to inform the user about such a failure? One way is to use the built-in server side validation to artificially push the error as a validation failure.


  19. Published: 15-Sep-2021
    This article starts with a brief primer on server side validations and why they should be done. A simple model of just one property is used to explain the whole process - starting from setting the validation error messages to finally inserting validation tags to render the errors. We explain how "asp-validation-for" attributes can be used to display validation errors, and that too, respectively, for each property and at a location just adjacent to its FORM element(see the screenshot below), and also how the ASP.NET Core engine takes care of almost 99% of your work. We also explain how to, optionally, display a gist of all validation errors using the "asp-validation-summary" attribute.


  20. Published: 14-Sep-2021
    A form submit is triggerred by a submit button inside FORM tags. If the method is POST, which is most often the case, then the recommended handler is OnPostAsync. The method should be asynchronous because FORM data is invariably processed through database INSERT and UPDATE queries, which must be done asynchronously. The submitted data can be extracted through the two-way BindProperty. See the linked video for a better understanding.


  21. Published: 14-Sep-2021
    This is an introduction to the most common UI Elements that can be used on a FORM. The article starts with a quick introduction to an html form of only one textbox, and then shows how to translate it to a razor form. Then a checkbox, a radiobuttonlist, and a dropdown are successively added one by one to build a full blown razor form. Data is not posted, a topic reserved for the next tutorials.


  22. Published: 13-Sep-2021
    An anchor tag helper can be used to specify the name of the click event handler. For this the attribute "asp-page-handler" is set equal to the name of the function in the backing class. Read through this tutorial to understand the whole idea. A video is also attached for a first-hand explanation. The tutorial concludes with a walkthrough that demonstrates how a click event can be handled on the server side.


  23. Published: 12-Sep-2021
    Tag helpers provide a standard way of generating html tags in razor pages. They are interpreted on server side. They are of the same syntax as html tags, so a web-designer can style and script them as he does any other html tag. Razor pages are not enabled for tag helpers by default. In this tutorial we learn how to enable a razor page for tag helpers, and we also learn a walkthrough on using the most common "anchor tag helper" to navigate from one razor page to another.


  24. Published: 11-Sep-2021
    This is a quick and complete explanation of how to integrate your razor pages to a framework such as bootstrap, and how to add and manage your custom CSS, JS and image files in your application. We explain various files such as the _ViewStart file, the _Layout file, and the special directory wwwroot. The concept is similar to that of master pages in the classic ASP.NET. The article also contains a linked video that you can watch for a clearer understanding of how we have integrated bootstrap to a simplest ASP.NET Core application.


  25. Published: 09-Sep-2021
    This is the simplest introduction to Razor Pages - why you need them, what they are, and how page events and data could be handled with them. See the linked video for a primer information.


  26. Published: 07-Sep-2021
    This tutorial extends the FORM that we have implemented in the previous tutorial (see link below). Now we add a dropdownlist to that form and observe how easy is it to make an addition to a project that is already CRUD-ready! A dropdownlist must be backed by a C# collection of SelectListItem objects. We also explain how to add an empty required [-Select-] item to such a dropdownlist.


  27. Published: 06-Sep-2021
    This tutorial extends the FORM that we have implemented in the previous tutorial (see link below). Now we add a radiobuttonlist to that form and observe how easy is it to make an addition to a project that is already CRUD-ready! The radiobuttonlist is backed by a hard-coded C# enumeration. We also explain how to specify the conversion from an enum to an INT data-type on the database side.


  28. Published: 05-Sep-2021
    This tutorial extends the one-textbox FORM that we have implemented for CRUD operations in the previous tutorial (see link below). Now we add a checkbox to that form and observe how easy is it to make an addition to a project that is already CRUD-ready!


  29. Published: 04-Sep-2021
    TempData can be used to pass data from one razor page to another. Although QueryString and Session variables can be used to achieve the same objective, yet TempData provides a briefer and cleaner way, and most importantly, it is built into the ASP.NET framework. The most attractive feature of TempData is that the data is automatically cleared away after a first read/extract operation - whenever it takes place. The tutorial ends with a walkthrough where TempData is saved in one page and used for showing a message on a second page. The message appears only once.


  30. Published: 03-Sep-2021
    This tutorial discusses the most desired scenario where data entry form and the already existing records are shown on the same page. Each record has an edit link adjacent to it. When this link is clicked, the record appears in the same data-entry form, so that the user can make changes and submit it. See the image below for a quick understanding of the problem being addressed here. This tutorial also explains a general scheme for editing with EF Core.


  31. Published: 31-Aug-2021
    We start by explaining the general scheme for deleting a record from a table. A foreach loop adds an anchor link to each record. The primary key (id) of each record is set as an attribute of each respective anchor link, and each anchor link also binds to a handler function in the backing class. When such a link is clicked the handler receives that id as a parameter and a C# code carries on the deletion.


  32. Published: 27-Aug-2021
    There is no built-in method for storing DateTime into a session variable in ASP.NET Core. However, the Microsoft MSDN docs suggest that developers can create their own extension methods on ISession, and they have provided code for one such pair of Set<T> and Get<T> methods that use json serialization to store any serializable type as a string. We have copy-pasted their code, and used it to create a small walkthrough that demonstrates how a DateTime instance can be stored in a session variable.


  33. Published: 26-Aug-2021
    This tutorial continues from where we left the tutorial on INSERT query (see the link below for a recap). The code we discussed there has been extended to display the inserted data. In the first part of this tutorial we explain the minimal three basic things that must be done to display data on a razor page. Then we incorporate those additions into the index page and its backing class to show the whole idea in action.


  34. Published: 24-Aug-2021
    This article explains behind-the-scenes mechanism by which "Session" is implemented in ASP.NET Core. We also enumerate the four extension methods that ASP.NET Core provides for reading and writing session variables. After that we present a walkthrough where existence of a Session key is checked to conditionally show a login link, or to show her user-name along with a log-off link that clears the user-name from the Session cache.


  35. Published: 23-Aug-2021
    So this article starts by explaining the various aspects of a partial view from a practical, day-to-day perspective. We have totally removed those parts that are either redundant or too complicated to be of any use for a practical developer. Then we take a small 3-step walkthrough that shows how to create a partial view, and how to consume it in a razor page. We also explain how a conditional menu can be conveniently implemented using the ideas of partial views. Partial Views + Razor Components can add to the confusion of a developer, so we finally conclude with a comparison with razor components.


  36. Published: 18-Aug-2021
    Razor components are stand-alone, embeddable units that replace themselves with pure HTML, CSS and JS markup. They can accept parameters from the host page. We discuss below how they differ from partial pages, and we also discuss the structure of a component page, and also how to use the <component> tag to easily embed a component into a razor page.


  37. Published: 16-Aug-2021
    This is a comprehensive discussion on the need for "areas", and how to practically create "areas", and how, un-like classic MVC, routing occurs out-of-the-box when razor pages are used. We also discuss how tag helpers help us create proper anchor links to pages inside areas. In the end we present a practical login and authorization scheme for projects that use areas.


  38. Published: 15-Aug-2021
    _ViewImports.cshtml is shared by all the razor pages in its peer directory, and in the sub-directories below it. It is like an include file, and it is used to type a list of common directives that would otherwise have to be typed in each of the razor pages. A razor page takes into account the entire hierarchy of _ViewImports files above it.


  39. Published: 14-Aug-2021
    This is a walkthrough on how to obtain user consent for usage of cookies on an asp.net core website. This project uses the ITrackingConsentFeature interface to determine if the user has already given his consent, and also to obtain the correct cookie string as per the http format. The readymade functions of this interface make it extremely easy for a developer to obtain a user's consent.


  40. Published: 13-Aug-2021
    We start this walkthrough with a small introduction to the concept of a cookie, and then we explain the various ASP.NET Core snippets to (a) create a cookie, (b) read a cookie and (c) delete a cookie. And lastly, we create a fully functional application for creating and deleting cookies. You can run the application to see the whole concept in action! We strongly recommend that you watch the linked video for finer details.


  41. Published: 12-Aug-2021
    A form of only one input textbox is POSTed and the data is inserted into a sqlite database. This is a six step walkthrough that starts from creating a model, followed by a DAL based on the DbContext class. We also explain how an application is configured for dependency injection of the DbContext, and also, how the DbContext is extracted from the constructor of a PageModel class, and ultimately used to run a database query.


  42. Published: 08-Aug-2021
    Here is a to-the-point tutorial on how database connectivity works in ASP.NET Core. A 3-step roadmap is laid for running your first query to a database of your choice. The tutorial concludes with an example walkthrough on adding nuget packages for a sqlite database. The actual database connectivity is done in later tutorials.


  43. Published: 07-Aug-2021
    This is a walkthrough on how to make calls to an XML database via repository pattern and dependency injection. We also give a brief introduction to the repository pattern and dependency injection, and also explain the associated benefits.


  44. Published: 06-Aug-2021
    This is the simplest example of reading and updating a record. For simplicity, the record consists of just one property called Name. An input textbox is used to display the "Name" and the same textbox is used to post the updated value. Reading and writing is done with the built-in XMLSerializer class.


  45. Published: 05-Aug-2021
    Looking for the "protected" App_Data folder in ASP.NET Core? The news is that it doesn't have that status anymore. It is no longer a "Special" folder. However, a workaround exists, and I demonstrate it in this tutorial. This tutorial explains how to read the contents of a notepad file (located in a "protected" folder of any random name). The contents are read from within the application, and displayed. Later we verify that the same notepad file cannot be accessed from the browser. This concept can easily be extended to use XML as a database, a topic we shall explore in some future posts.


  46. Published: 25-Mar-2021
    Anti-forgery token is NOT available outside of <form> tags. This article, alongwith the appended video, explains how to use IAntiforgery service to solve this limitation, and POST data, especially as an AJAX request, when a full-fledged form is not possible?


  47. Published: 22-Mar-2021
    Simplest explanation of AJAX based Edit, Update, Cancel operations on a row of an HTML table. An ASP.NET Core POST handler receives the updated values that can be processed for an update to a database.


  48. Published: 20-Mar-2021
    Pure Javascipt and html5 based general solution for in-place or in-line editing of the tr, td records of an html table. This solution is suitable for ajax based updates of the rows of a table. We shall demonstrate the concept with just one input text, but this solution can easily be extended to include dropdowns, radio buttons and checkboxes:


  49. Published: 16-Mar-2021
    In brief: Just two additions are required to implement AJAX based authorization in your existing ASP.NET Core application - first is on the javascript side - where the response code should be tested, and second on the server side where User.IsInRole has to be tested. The concept is explained in the text that follows, and a working example is described in the appended youtube video!


  50. Published: 11-Mar-2021
    This project is about creating an Admin Panel that would be suitable for a reporting project or an EBook that shows a table of links on the left and the corresponding content on the right side. The content is obtained by an Ajax call to an ASP.NET Core application. Source code for all the three files has been given and explained below.


  51. Published: 09-Mar-2021
    In nutshell: The selection change event of the master dropdown is used to send the "id" of the selected item to the server, which sends back a collection of items for the slave dropdown. A javascript based Ajax GET request is used for this communication with the server.


  52. Published: 05-Mar-2021
    The following project has a textbox with a send button. The click event fires an AJAX GET request and sends a string parameter to an ASP.NET Core application, which responds by converting the parameter to its uppercase equivalent. The client side script has been written using pure javascript.


  53. Published: 03-Mar-2021
    How to POST an ASP.NET Core Razor FORM through an Ajax Request. We discuss a practical approach that is to-the-point and easy to understand. The given code is ready to copy-paste!


  54. Published: 27-Sep-2020
    Some, not all, routes need a daily downtime between 17 hrs to 18 hrs. So they have to be shut during that period so that no requests are processed. Any request has to be redirected to another page or a website, say, hoven.in. How should that be implemented?


  55. Published: 25-Sep-2020
    Write an ASP.NET Core application such that the route "/home/index/N", where N is any int number, executes only if the website is hosted on port 67291 of "hoven.in" or "www.hoven.in". It should return 404 even if it is hosted on any subdomain like "*.hoven.in:67291"?


  56. Published: 23-Sep-2020
    This is a summary of the concepts of routing and route templates in asp.net core. We have taken a practical exercise to develop the concepts in an interesting way.


  57. Published: 18-Sep-2020
    Use the concepts learnt till now, and without using razor, and without mvc framework, create a contact form that has a text box (cusName) and a date picker (meetOn), and that posts data to your asp.net core application. The application echoes this data back to the browser.


  58. Published: 16-Sep-2020
    This tutorial explains everything necessary to get you started with the middleware in ASPNET Core. We explain the built-in middleware components as well as the Use, Map and Run extension methods through practical code.


  59. Published: 03-Sep-2020
    This tutorial explains the Startup class in ASP.NET, along with the methods of this class. We also explain how a custom middleware can be attached by IStartupFilter.