ASP.NET Core – ScottGeek Technology https://scottgeek.technology Thu, 12 Nov 2020 01:17:33 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 Dot Net 5 is Here… Check it out. https://scottgeek.technology/2020/11/11/dot-net-5-is-here-check-it-out/ https://scottgeek.technology/2020/11/11/dot-net-5-is-here-check-it-out/#respond Thu, 12 Nov 2020 01:17:33 +0000 https://scottgeek.technology/?p=5253 Wow… some most excellent videos on what is what in .Net 5! Check it out on

[visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly93d3cuZG90bmV0Y29uZi5uZXQvIiwiaW1hZ2VfaWQiOjAsImltYWdlX3VybCI6IiIsInRpdGxlIjoiLk5FVCBDb25mIDIwMjAiLCJzdW1tYXJ5IjoiSm9pbiB0aGUgLk5FVCBDb25mIDIwMjAgZnJlZSB2aXJ0dWFsIGV2ZW50IE5vdmVtYmVyIDEwLTEyIHRvIGxlYXJuIGFib3V0IHRoZSBuZXdlc3QgZGV2ZWxvcG1lbnRzIGFjcm9zcyB0aGUgLk5FVCBwbGF0Zm9ybSwgb3BlbiBzb3VyY2UsIGFuZCBkZXYgdG9vbHMuIE1hcmsgeW91ciBjYWxlbmRhciEiLCJ0ZW1wbGF0ZSI6InVzZV9kZWZhdWx0X2Zyb21fc2V0dGluZ3MifQ==”]

You can also find these on You Tube… search on .Net 5. The Conf 2020 Days 1-3 will be there…

~ScottGeek.

]]>
https://scottgeek.technology/2020/11/11/dot-net-5-is-here-check-it-out/feed/ 0
The Server Side Blazor and SignalR Timeout https://scottgeek.technology/2020/06/13/the-server-side-blazor-and-signalr-timeout/ https://scottgeek.technology/2020/06/13/the-server-side-blazor-and-signalr-timeout/#respond Sat, 13 Jun 2020 20:20:25 +0000 https://scottgeek.technology/?p=5161 So in my Blazor travels I ran across one (or another) annoying thing. In this one we will talk about that Server -Timeout? Disconnect? Retry? Not really sure which one it is.
This affects Blazor Server Side where SinalR is being used between the browser and server side code.image

 

 

I came across some Javescript that can go into the _Host.cshtml file.

<script>
    // Wait until a 'reload' button appears
    new MutationObserver((mutations, observer) => {
        if (document.querySelector('#components-reconnect-modal h5 a')) {
            // Now every 10 seconds, see if the server appears to be back, and if so, reload
            async function attemptReload() {
                await fetch(''); // Check the server really is back
                location.reload();
            }
            observer.disconnect();
            attemptReload();
            setInterval(attemptReload, 10000);
        }
    }).observe(document.body, { childList: true, subtree: true });
</script>

Not really a solution but let’s see. The script is basic and checks the connection and reloads the page as needed.

There’s a full run down here ASP Core Issues. Another good resource is this docs page ASP.NET Core SignalR configuration.

Happy Blazor-ing!

~ScottGeek

 

]]>
https://scottgeek.technology/2020/06/13/the-server-side-blazor-and-signalr-timeout/feed/ 0
ASP .Net Core Razor SPA vs. MVC Taghelpers Navigation https://scottgeek.technology/2019/06/27/asp-net-core-razor-spa-vs-mvc-taghelpers-navigation/ https://scottgeek.technology/2019/06/27/asp-net-core-razor-spa-vs-mvc-taghelpers-navigation/#respond Thu, 27 Jun 2019 13:02:28 +0000 https://scottgeek.technology/?p=5061 As I mess about with deciding- do I want to do Razor SPA pages or do a full on ASP.Core MVC pages for my latest Web App? I noticed something when- Yes I put both in a solution- it comes to the ASP tag helper for navigation links…

So here’s the thing. For a regular ASP.Core MVC we see tag helper navigations look like this:

<a class="nav-link" asp-controller="Home" asp-action="Index">Home</span></a>

Simple enough… “asp-controller”  has the simple controller name, and  “asp-action” the action within the controller… no problem

Now consider Razor SPA or just simple razor pages:
 

<a class="nav-link text-dark btn btn-outline-info" asp-page="/Index" data-toggle="tooltip" data-placement="top" title="Always Takes you back Home">Home</a>

Here we have a “asp-page”.  Ok, I do get it… Razor SPA or Razor Pages do not follow the MVC pattern with a controller etc. But why do they need to be different? Yes I understand MVC came first and it is very understandable to have a clear navigation tag helper. But again, why not just one simple tag helper that sorts out where the page and/or controller is?

This gets even more complex – mostly- when one considers “Areas”.

Again very well defined for an MVC pattern. But to use within Razor Pages, you have to muck about with making sure this is available in your Startup.ConfigureServices. Why oh WHY?

services.AddMvc()
        .AddRazorPagesOptions(options => options.AllowAreas = true);

Maybe some day this will evaporate, but for now…  no.

fyi… as this applies to ASP.Net Core 2.2, the doc reference is here:

Anchor Tag Helper in ASP.NET Core

Anchor Tag Helper in ASP.NET Core

Discover the ASP.NET Core Anchor Tag Helper attributes and the role each attribute plays in extending behavior of the HTML anchor tag.

Source: docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-2.2

 

Happy tagging,
~SG

 

 

]]>
https://scottgeek.technology/2019/06/27/asp-net-core-razor-spa-vs-mvc-taghelpers-navigation/feed/ 0
Using Kestrel for ASP Core Apps https://scottgeek.technology/2019/03/03/using-kestrel-for-asp-core-apps/ https://scottgeek.technology/2019/03/03/using-kestrel-for-asp-core-apps/#respond Sun, 03 Mar 2019 18:04:30 +0000 https://scottgeek.technology/?p=1736 As I was looking about with some of the Core 2.2 notes, I came across some interesting notes on how to tweak about with Kestrel settings….

I’m not sure I like putting Kestrel options up the in the Main Program builder. I tend to prefer these to collect in the startup class, but I get point of why Kestrel needs to be handled close to the Builder (it is after all the html service handling web calls).

Shall we begin…
So up in program.cs we do our normal Web Host Builder:

public class Program
{
    public static void Main(string[] args)
    {
        var host = CreateWebHostBuilder(args).Build();

        MigrateDatabase(host);

        host.Run();
        //CreateWebHostBuilder(args).Build().Run();
    }

    private static void MigrateDatabase(IWebHost host)
    {
        using (var scope = host.Services.CreateScope())
        {
            var db = scope.ServiceProvider.GetRequiredService&lt;ApplicationDbContext>();
            db.Database.Migrate();
        }
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup&lt;Startup>();
}

This tends to be my way of doing Program.cs. Note I split out the Build part into a static method (the normal default way is to have one fluent state that does a build and run in single line- it’s that commented line in the Main method) 

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup$lt;Startup>()
                .ConfigureKestrel(opts =>
                {
                    opts.Limits.MaxConcurrentConnections = 100;

                });

 In my example, the method I push Kestrel setting to would of course have the .ConfigureKestrel with it’s options settings… 

Check it out… lots of interesting tweaks on settings…

You will find some details here on MS DOCS:

Learn about Kestrel, the cross-platform web server for ASP.NET Core.

 

]]>
https://scottgeek.technology/2019/03/03/using-kestrel-for-asp-core-apps/feed/ 0
EF Migration tasks in the Program.cs – The good and the Ugly https://scottgeek.technology/2019/02/18/ef-migration-tasks-in-the-program-cs-the-good-and-the-ugly/ https://scottgeek.technology/2019/02/18/ef-migration-tasks-in-the-program-cs-the-good-and-the-ugly/#respond Mon, 18 Feb 2019 18:28:47 +0000 https://scottgeek.technology/?p=907 Program.cs of any core project (especially ASP.Net Core) is our first starting point to get some necessary work out of the wrong. In this case EF DB Migrations. You know that EF thing where you keep your attached DB tables in sync with your data models? (or in some cases… mess up your existing database).

Life in program.cs normally starts here:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup&lt;Startup>();
}

But let’s consider this:

 

public class Program
{
    public static async Task Main(string[] args)
    {
        IWebHost webHost = CreateWebHostBuilder(args).Build();

        // Create a new scope
        using (var scope = webHost.Services.CreateScope())
        {
            // Get the DbContext instance
            var myDbContext = scope.ServiceProvider.GetRequiredService&lt;MyDbContext>();

            //Do the migration asynchronously
            await myDbContext.Database.MigrateAsync();
        }

        // Run the WebHost, and start accepting requests
        // There's an async overload, so we may as well use it
        await webHost.RunAsync();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup&lt;Startup>();
}

 

What the? So what is going on here… Well, basically we are injecting our EF DB Migration process between the creating of our web app (Build) and the actual Running of the site… You know that period of time when processes are defined and setup and actually begin listening on the wire.

 Have a look at this article….

https://andrewlock.net/running-async-tasks-on-app-startup-in-asp-net-core-part-1/

 

 

  

]]>
https://scottgeek.technology/2019/02/18/ef-migration-tasks-in-the-program-cs-the-good-and-the-ugly/feed/ 0
App Registration Link https://scottgeek.technology/2019/02/03/app-registration-link/ https://scottgeek.technology/2019/02/03/app-registration-link/#respond Sun, 03 Feb 2019 15:08:03 +0000 https://scottgeek.technology/?p=889 This seems to want to move me off to Azure…

But for now the link still works…

https://apps.dev.microsoft.com

]]>
https://scottgeek.technology/2019/02/03/app-registration-link/feed/ 0
ASP .NET Core – the new stuff https://scottgeek.technology/2018/08/05/asp-net-core-the-new-stuff/ https://scottgeek.technology/2018/08/05/asp-net-core-the-new-stuff/#respond Sun, 05 Aug 2018 01:32:43 +0000 https://scottgeek.technology/?p=686 The latest read concerning ASP.Net Core 2.1

[visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9tc2RuLm1pY3Jvc29mdC5jb20vZW4tdXMvbWFnYXppbmUvbXQ4Mjk3MDYiLCJpbWFnZV9pZCI6Njg3LCJpbWFnZV91cmwiOiJodHRwczovL3Njb3R0Z2Vlay50ZWNobm9sb2d5L3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDE4LzA4L0lDODc5ODU5LmpwZyIsInRpdGxlIjoiQVNQLk5FVCBDb3JlIC0gV2hhdCdzIE5ldyBpbiBBU1AuTkVUIENvcmUgMi4xIiwic3VtbWFyeSI6Ik1pY3Jvc29mdCByZWNlbnRseSByZWxlYXNlZCBBU1AuTkVUIENvcmUgMi4xIGFsb25nIHdpdGggLk5FVCBDb3JlIDIuMSBhbmQgRW50aXR5IEZyYW1ld29yayAoRUYpIENvcmUgMi4xLiBDb21iaW5lZCwgdGhlc2UgcmVsZWFzZXMgb2ZmZXIgc29tZSBncmVhdCBpbXByb3ZlbWVudHMgaW4gcGVyZm9ybWFuY2UsIGFzIHdlbGwgYXMgYWRkaXRpb25hbCBmZWF0dXJlcyBmb3IgLk5FVCBDb3JlIGRldmVsb3BlcnMuIE1pY3Jvc29mdCBpcyBhbHNvIG9mZmVyaW5nIExvbmctVGVybSBTdXBwb3J0IChMVFMpIHdpdGggdGhpcyByZWxlYXNlLCBtZWFuaW5nIGl0IHdpbGwgcmVtYWluIHN1cHBvcnRlZCBmb3IgdGhyZWUgeWVhcnMuIFRoaXMgYXJ0aWNsZSBwcm92aWRlcyBhbiBvdmVydmlldyBvZiB0aGUgaW1wcm92ZW1lbnRzIGluIEFTUC5ORVQgQ29yZSAyLjEuIFRvIGxlYXJuIG1vcmUgYWJvdXQgd2hhdOKAmXMgbmV3IGluIEVGIENvcmUgMi4xLCBjaGVjayBvdXQgdGhpcyBtb250aOKAmXMgRGF0YSBQb2ludHMgY29sdW1uIGJ5IEp1bGllIExlcm1hbiwg4oCcRGVlcCBEaXZlIGludG8gRUYgQ29yZSBIYXNEYXRhIFNlZWRpbmfigJ0gYW5kIGhlciBjb2x1bW4gbGFzdCBtb250aCAobXNkbi5jb20vbWFnYXppbmUvbXQ4NDcxODQpIHRoYXQgIGRlbHZlcyBpbnRvIHRoZSBuZXcgRUYgQ29yZSAyLjEgUXVlcnkgVHlwZSBmZWF0dXJlLCB3aGljaCBsZXRzIHlvdSBtb3JlIGVhc2lseSBxdWVyeSBhIGRhdGFiYXNlIHdpdGhvdXQgbmVlZGluZyB0cnVlIGVudGl0aWVzIHdpdGgga2V5IHByb3BlcnRpZXMgdG8gY29uc3VtZSB0aGUgcmVzdWx0cy4iLCJ0ZW1wbGF0ZSI6ImRlZmF1bHQifQ==”]

]]>
https://scottgeek.technology/2018/08/05/asp-net-core-the-new-stuff/feed/ 0
ASP.Net Core Identity and Bootstrap 4 https://scottgeek.technology/2018/07/02/asp-net-core-identity-and-bootstrap-4/ https://scottgeek.technology/2018/07/02/asp-net-core-identity-and-bootstrap-4/#respond Mon, 02 Jul 2018 17:54:09 +0000 https://scottgeek.technology/?p=501 UPDATING ASP.NET CORE IDENTITY TO USE BOOTSTRAP 4

I still need to read this: The Article

How to Scaffold Identity UI in ASP.NET Core 2.1:  Scaffold Article

 

]]>
https://scottgeek.technology/2018/07/02/asp-net-core-identity-and-bootstrap-4/feed/ 0
Article: Looks like .Net Core 2.1 preview 2 is here. https://scottgeek.technology/2018/04/20/article-looks-like-net-core-2-1-preview-2-is-here/ https://scottgeek.technology/2018/04/20/article-looks-like-net-core-2-1-preview-2-is-here/#respond Fri, 20 Apr 2018 11:39:57 +0000 https://scottgeek.technology/?p=219 I’ve not even finished looking at the 1st preview – with a read though. Seems there’s come controversy starting with how previews roll form version to version. It seems a bit pointless to me. I understand the “breaking” changes, and I have no issue with the change in policy. Read the article.

Announcing .NET Core 2.1 Preview 2

 

]]>
https://scottgeek.technology/2018/04/20/article-looks-like-net-core-2-1-preview-2-is-here/feed/ 0
GitHub: Develop ASP.NET Core Applications in a Container https://scottgeek.technology/2018/04/20/github-develop-asp-net-core-applications-in-a-container/ https://scottgeek.technology/2018/04/20/github-develop-asp-net-core-applications-in-a-container/#respond Fri, 20 Apr 2018 11:31:36 +0000 https://scottgeek.technology/?p=217 Interesting and useful GitHub repo for getting started with “Containerized” Core development. 

Develop ASP.NET Core Applications in a Container

]]>
https://scottgeek.technology/2018/04/20/github-develop-asp-net-core-applications-in-a-container/feed/ 0