net50

PineBlog v2

PineBlog has been updated to version 2. This new release adds the following new features and improvements:

  • MongoDb can now be used a data source
  • Extended Markdown support
  • Now targeting net5.0 and netcoreapp3.1
  • Removed the _ValidationScriptsPartial from Opw.PineBlog.RazorPages
  • Removed dependencies on Opw.Core and Opw.EntityFramework

Build Status NuGet Badge License: MIT

Using MongoDb

When you want to use MongoDb as your database, then you don't use the Opw.PineBlog metapackage but you need to install the required packages individually.

  • Opw.PineBlog.MongoDb package The PineBlog data provider that uses MongoDb. NuGet Badge

  • Opw.PineBlog.RazorPages package The PineBlog UI using ASP.NET Core MVC Razor Pages. NuGet Badge

  • Opw.PineBlog.Core package The PineBlog core package. This package is a dependency for Opw.PineBlog.RazorPages and Opw.PineBlog.MongoDb. NuGet Badge

Startup

You add the PineBlog services and the Razor Pages UI in the Startup.cs of your application.

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddPineBlogCore(Configuration);
    services.AddPineBlogMongoDb(Configuration);

    services.AddRazorPages().AddPineBlogRazorPages();
    // or services.AddMvcCore().AddPineBlogRazorPages();
    // or services.AddMvc().AddPineBlogRazorPages();
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

    // Make sure you enable static file serving
    app.UseStaticFiles();

    ...
    app.UseEndpoints(endpoints =>
    {
        // make sure to add the endpoint mapping for both RazorPages and Controllers
        endpoints.MapRazorPages();
        endpoints.MapControllers();
    });
    ...
}

NOTE: Make sure you enable static file serving app.UseStaticFiles();, to enable the serving of the css and javascript from the Opw.PineBlog.RazorPages packages.

Configuration

And a few properties need to be configured before you can run your web application with PineBlog.

{
    "ConnectionStrings": {
        "MongoDbConnection": "inMemory" // MongoDb connection string
    },
    "PineBlogOptions": {
        "Title": "PineBlog",
        "Description": "A blogging engine based on ASP.NET Core MVC Razor Pages and MongoDb",
        "ItemsPerPage": 5,
        "CreateAndSeedDatabases": true,
        "ConnectionStringName": "MongoDbConnection",
        "MongoDbDatabaseName": "pineblog-db",
        "AzureStorageConnectionString": "UseDevelopmentStorage=true",
        "AzureStorageBlobContainerName": "pineblog",
        "FileBaseUrl": "http://127.0.0.1:10000/devstoreaccount1"
    }
}

Blog Settings ConfigurationProvider

To be able to update the blog settings from the admin pages, you need to add the PineBlog IConfigurationProviders to the IConfigurationBuilder in the Program.cs. Add config.AddPineBlogMongoDbConfiguration(reloadOnChange: true); to ConfigureAppConfiguration(..) on the IWebHostBuilder.

WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .ConfigureAppConfiguration((hostingContext, config) => {
        config.AddPineBlogMongoDbConfiguration(reloadOnChange: true);
    });

Markdown support

Markdig is used as the Markdown processor and the following markdown features are enabled by default:

If you want or require more advanced Markdown features, you can enable those by overriding the ~/Areas/Blog/Pages/Shared/_Post.cshtml partial (see source).

Tables

How to create the following table with styling, using pipe tables and generic attributes.

Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
{.table .table-striped}
|Company|Contact|Country|
|-|-|-|
|Alfreds Futterkiste|Maria Anders|Germany|
|Centro comercial Moctezuma|Francisco Chang|Mexico|
|Ernst Handel|Roland Mendel|Austria|
|Island Trading|Helen Bennett|UK|

Using CSS

How to create the following blockquote with an bootstrap info-alert style, using generic attributes.

Normally the dangers inherent in the diverse hardware environment enhances the efficiency of the inductive associative dichotomy on a strictly limited basis.

{.alert .alert-info}
> Normally the dangers inherent in the diverse hardware environment enhances the efficiency of the inductive associative dichotomy on a strictly limited basis.

.Net 5.0

The PineBlog packages are now targeting targeting net5.0 and netcoreapp3.1.

Where can I get it?

You can install the Opw.PineBlog metapackage from the console.

> dotnet add package Opw.PineBlog

The Opw.PineBlog metapackage includes the following packages.

  • Opw.PineBlog.EntityFrameworkCore package The PineBlog data provider that uses Entity Framework Core. NuGet Badge

  • Opw.PineBlog.RazorPages package The PineBlog UI using ASP.NET Core MVC Razor Pages. NuGet Badge

  • Opw.PineBlog.Core package The PineBlog core package. This package is a dependency for Opw.PineBlog.RazorPages and Opw.PineBlog.EntityFrameworkCore. NuGet Badge

  • Opw.PineBlog.MongoDb package The PineBlog data provider that uses MongoDb. NuGet Badge

Demo website

Check out the PineBlog demo website. You can write and publish posts, upload files and test application before install. And no worries, it is just a sandbox and will clean itself.

Url: pineblog.azurewebsites.net
Username: pineblog@example.com
Password: demo

HttpExceptions v3

HttpExceptions has been updated to version 3 (3.0.2). This new release adds the following new features:

  • New options to override the Exception*Mapping and HttpContext*Mapping methods on the mappers
  • Expose serialization helper methods in the Opw.HttpExceptions.AspNetCore package
  • Opw.HttpExceptions.AspNetCore package is now targeting net50 and .NETCoreApp 3.1

Override the *Mapping methods

New options to override the Exception*Mapping and HttpContext*Mapping methods on the mappers using a Func have been added.

You can inject your own mappings for the ProblemDetails properties using functions on the HttpExceptionsOptions, or by creating your own IExceptionMapper and/or IHttpResponseMapper. If you inject your own function that will be tried first, and if no result is returned the defaults will be used.

In the following example we will create a custom function mapping the ProblemDetails.Type property. By default the ProblemDetails.Type property will be set by:

  1. Either the Exception.HelpLink or the HTTP status code information link.
  2. Or the DefaultHelpLink will be used.
  3. Or an URI with the HTTP status name ("error:[status:slug]") will be used.

When the ExceptionTypeMapping or HttpContextTypeMapping are set the result of those functions will be tried first, if no result is returned the defaults will be used.

mvcBuilder.AddHttpExceptions(options =>
{
    ExceptionTypeMapping = exception => {
        // This is a example, you can implement your own logic here.
        return "My Exception Type Mapping";
    },
    HttpContextTypeMapping = context => {
        // This is a example, you can implement your own logic here.
        return "My HttpContext Type Mapping";
    }
});

Serialization helpers

Serialization helper methods added to the Opw.HttpExceptions.AspNetCore package.

Serialize the HTTP content to ProblemDetails.

ProblemDetails problemDetails = ((HttpContent)response.Content).ReadAsProblemDetails();

Try to get the exception details from the ProblemDetails.

SerializableException exception;
((ProblemDetails)problemDetails).TryGetExceptionDetails(out exception);

Try to get the errors dictionary from the ProblemDetails.

var IDictionary<string, object[]> errors;
((ProblemDetails)problemDetails).TryGetErrors(out errors);

.Net 5.0

The Opw.HttpExceptions.AspNetCore package is now targeting net50 and .NETCoreApp 3.1.

Where can I get it?

The code can be found on GitHub at: github.com/ofpinewood/http-exceptions. And there is also a sample project you can have a look at.

You can install the Opw.HttpExceptions and Opw.HttpExceptions.AspNetCore NuGet packages from the package manager console:

PM> Install-Package Opw.HttpExceptions
PM> Install-Package Opw.HttpExceptions.AspNetCore