Subscribe: Rick Strahl's Web Log
http://www.west-wind.com/weblog/rss.aspx
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
application  browser  client side  client  core  files  install  markdown monster  net core  net  routes  web browser  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Rick Strahl's Web Log

Rick Strahl's Web Log



Life, Surf, Code and everything in between



 



Handling HTML5 Client Route Fallbacks in ASP.NET Core

Mon, 07 Aug 2017 17:40:07 GMT

When using client side applications built with application frameworks like Angular, React, Vue and so on, you will invariably deal with HTML5 client side routing, which handles client side routes to pages and components entirely in the browser. Well almost entirely in the browser... HTML5 client routes work great on the client, but when deep linking into a site or pressing Refresh in the browser, client side routes have a nasty habit of turning into server HTTP requests. Requests to routes that the server is likely not configured for. In this post I discuss what you have to do to have your ASP.NET Core (or indirectly ASP.NET application) handle these 'fake' requests by effectively re-attaching the client side application to its routes. Html 5 Client Side Routing? If you don't know what HTML5 client side routing is, here's a quick refresher. Client side frameworks implement their own client side routing mechanisms so they can - just like server applications - navigate from page to page or component. Angular supports a couple of route types: Hash bang routes (http://localhost:4200/#!/albums or http://localhost:4200/#/albums) HTML 5 Routes (http://localhost:4200/albums) #!/ Hash Bang Routes The former is an older approach that works directly with the HTTP semantics that specify that any URL with a # is fired on the client and jumping to a 'local' URL within the page. Frameworks can intercept the navigation and examine the URL content following the # to determine the route. The hash bang #!\ is used to differentiate application urls from plain # anchor links. The nice thing about hash bang routes is that they just work. There's no server side bleeding of the routes and if you bookmark or refresh the client side page it just works as expected because the hash logic is executed as part of the native URL parsing in the browser. Easy, right? It just works. But the downside is that the URLs are pretty ugly and non-intuitive if you have ever have to type it in manually. Not really a great argument against hash bang routes, but regardless they are falling out of favor to HTML5 routing. Hash Bang Routes in Angular Angular uses HTML5 Client routes by default, but it's a simple switch to enable Hashbang routes instead of HTML5 routes:: // in app.module.ts providers : [ .. // make sure you use this for Hash Urls rather than HTML 5 routing { provide: LocationStrategy, useClass: HashLocationStrategy }, ] As long as you use routerLink for your link URLs in HTML templates, and router.navigate() for in-code links, Angular switches automatically between the two modes. In HTML use links In code use: router.navigate(["/album",album.id]) HTML5 Routing HTML5 routing uses a more sophisticated approach - it uses HTML5's Pushstate API to control the routes on the client side and manage the address bar display. The advantage of this approach is that is easily controllable with this relatively easy to work with HTML5 API and the URLs are much cleaner, using standard extensionless route conventions you expect from Web applications and APIs today. But HTML5 routes require explicit support from the server to appropriately understand which routes are server routes and which are client routes. HTML5 Route Problems without Server Handling The problem is that HTML5 client routes are indistinguishable from server routes. http://localhost:4200/albums can just as easily be a client side URL as a server side URL. While navigating entirely on the client, HTML5 routes work fine - the application can intercept navigation and route to the appropriate client side pages when a specific route is activated. The problem pops up if you have navigated into a client driven application with a deep link and you then bookmark the page and later navigate back to it with that URL, or you refresh the current active page. In both cases the client application isn't running when the route is requested by the browser and so the browser requests the routed URL from the server. But by default isn't [...]



Updating Windows Applications and Installers for non-Admin Installation

Tue, 18 Jul 2017 06:54:04 GMT

A couple of weeks ago I updated Markdown Monster to run as a fully portable application that no longer requires administrative privileges to install. Yay! The installer now doesn't trigger admin elevation and the resulting installation is a free standing install that can either be installed with the Installer or installed as a portable install simply by copying files out of a Zip folder. There are also corresponding Chocolatey installers for both full and portable installs. The full installer still installs a few settings in the registry and desktop shortcuts etc, but all of the important registry settings are now made in the User's Registry hive and are totally optional. If using a Portable install or simply copying files, Markdown Monster checks for each of these configuration settings on startup and internally sets them as part of the startup. I've been surprised that there have been a lot of requests for having an admin-less install. Personally I prefer a full install that shows up in Programs and Features with full uninstall support, but now with these changes I can actually have an admin-less install and still get that system installer registration. Meet the cake... and Im eating it! It's been a slow process getting here - knocking off one feature at a time, some of which (namely the extension mapping) I thought weren't actually possible as non-admin feature, as they aren't well documented. But I'm excited to see that Markdown Monster now runs of a very light touch installer. In this post I describe the various steps of making the existing install work which might give those of you that want to do something similar the tools to do the same. Moving Folder Location Originally Markdown Monster was installed in Program Files (x86). Installing an application in this folder hierarchy automatically means that the installer has to run as an Administrator in order to be able to write files in that folder structure (unless the user has changed permissions explicitly). The typical installer ideology is that Program Files is meant for statically installing an application that after install cannot be changed. The main brunt of the recent update which included the move to the Admin-less install in version 1.4, is about the new location in the %LocalAppData%\Markdown Monster folder. LocalAppData is the 'fixed' user specific folder for a given user. The interactive user has full rights there and can read and write files. Note that there are 3 'AppData' folders: Typically you use %AppData% which maps the to the Roaming profile for user storing user data. Markdown Monster stores its configuration settings, installs Addins and their configurations here. %LocalAppData% maps to the Local folder and it's meant to house truly locally maintained data that is user and machine specific. In this case Markdown Monster installs here as each install is done locally on each machine. Frankly, I'm not sure what LocalLow is used for - on my machine I see only very few files there and they all look temporary and cached files. Markdown Monster installs in %LocalAppData% which allows installation without admin privileges. Files are simply copied into this folder and the application can run even if there's no installer at all. Portable Installation If you want a truly portable installation of Markdown Monster you could actually install the files in your DropBox, OneDrive or GoogleDrive folder and run it from there. It'd be available on any Windows machine that has Dropbox installed and MM will automatically configure itself the first time it runs. Missing are only shortcuts Installer Preferred I do recommend the installer to properly install and uninstall the various registry settings and files, but if desired the portable install can be installed from a simple file based zip archive and placed anywhere on disk to run. When running using the portable install the handful of registry settings in HKEY_CURRENT_USER are made by the Markdown Monster executable itself, which also means they won't be 'uninstalled'. There were[...]



JavaScript Debugging in a Web Browser Control with Visual Studio

Fri, 07 Jul 2017 02:24:15 GMT

Debugging a Web Browser Control embedded in a Windows application can be a bear because there's no obvious way to debug the the JavaScript code or HTML DOM/CSS inside of the application. Although the Web Browser uses the Internet Explorer Engine for HTML rendering and JavaScript execution and provides most of the engine features, the Debugger and F12 are not part of that. As it turns out you can use Visual Studio to hook up a script debugger and provide a rich debugging experience with the full IE debugger, Console and even a DOM/CSS Explorer. In this post I show how.(image)



Debouncing and Throttling Dispatcher Events

Mon, 03 Jul 2017 05:32:49 GMT

In UI applications it's not uncommon for a number of UI events to fire more events than your application can handle. In order to limit the number of events it's often a good idea to throttle or 'debounce' events so that only a single event is fire for a given period. In this post I describe a Dispatcher based implementation for debouncing and throttling UI events in WPF applications.(image)



Multi-Targeting and Porting a .NET Library to .NET Core 2.0

Thu, 22 Jun 2017 16:46:07 GMT

I've been holding off porting any of my full frameworks to .NET Core. With the latest .NET Core 2.0 and .NET Standard 2.0 releases and their vastly larger footprints that match more closely with what we expect of the .NET Framework feature set, migrating looks a lot more appealing. In this post I describe the process of porting one of my general purpose full framework libraries to .NET Standard 2.0 and in the process also creating a multi-targeted project that compiles .NET 4.5, 4.0 and .NET Standard projects.(image)



Bypassing IIS Error Messages in ASP.NET

Thu, 01 Jun 2017 22:30:42 GMT

IIS Error handling is the source of lots of confusion. I've been using IIS for nearly 20 years now, and figuring out the right combination of error configuration settings and code to properly serve custom error pages or error responses in API still makes fumble a few times before I get it just right. This post provides a few hints and some background on how to deal with error handling.(image)



Automating IIS Feature Installation with Powershell

Thu, 25 May 2017 19:30:28 GMT

IIS often gets a bad wrap for being diffcult to install and configure. However, using some of the built-in tooling for administration using PowerShell it's actually quite easy to configure IIS and even set up a new site and application pool with a few short scripts that are much quicker, and more repeatable than using the various Windows UI features. Here's how.(image)



Upgrading to .NET Core 2.0 Preview

Tue, 16 May 2017 04:42:00 GMT

With the release of the first preview of .NET Core 2 and ASP.NET Core 2.0 I decided to upgrade my AlbumViewer sample application to the latest bits and preview tools. Overall the experience was pretty smooth, but I ran into a couple of breaking changes and a few tooling snags that I'll describe in this post.(image)



IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing

Fri, 28 Apr 2017 02:26:44 GMT

If you're running ASP.NET Core under Windows with IIS, you'll want to take advantage of letting IIS serve up your static content and handle your HTML 5 Client and home routes. IIS is very efficient at handling static content and content re-routing and in this post I describe how you can properly configure ASP.NET Core applications using the AspNetCoreModule and IIS Rewrite Rules(image)



Creating a Markdown Monster Addin: Save Images to Azure Blob Storage

Mon, 17 Apr 2017 16:30:29 GMT

The Markdown Monster Markdown Editor and Weblog Publishing tool has a .NET based addin model that makes it relatively easy to extend its core feature set with custom functionality. In this post I show how you can quickly create an addin of your own, and then show a practical example that demonstrates how add Image uploading to Azure Blob storage as an interactive addin.(image)



Running .NET Core Apps under Windows Subsystem for Linux (Bash for Windows)

Thu, 13 Apr 2017 19:53:07 GMT

The Windows Shell for Linux (WSL or Bash on Ubuntu on Windows) provides a nice way for Windows and Linux to interact without the overhead of dealing with a separate VM. Using the WSL you can now also run your .NET Core applications directly under Linux without requiring a VM or Docker. In this post I demonstrate how the shell works and how you can run your .NET and ASP.NET Core applications to test operation under Linux.(image)



Virus Scanning Madness for Software Distribution

Sun, 02 Apr 2017 19:22:35 GMT

I've been having having lots of problems recently with VirusTotal, which is used by Chocolatey to scan for malware in Chocolatey distribution packages. VirusTotal is a Web based service that aggregates around 60 virus scanners against an installation binary. The problems is that I frequently see random malware hits by various obscure scanners. In this post I describe the problem and the farce that this has become as some of the malware hits are obviously false positives that actually reverse in a rescan.(image)



Updating my AlbumViewer Sample to ASP.NET Core 1.1 and Angular 4

Fri, 31 Mar 2017 08:05:54 GMT

I updated my AlbumViewer sample application recently to the latest versions of ASP.NET Core (1.1) and the new .csproj project as well Angular 4(image)



More on ASP.NET Core Running under IIS

Fri, 17 Mar 2017 05:40:45 GMT

Since my last post about hosting ASP.NET Core on IIS I've gotten quite a few questions and comments in regards to working with this mixed IIS/Kestrel hosting environment. There are quite a few not so obvious arrangement in this set up and some surprising discoveries in terms of performance and segragation of feature usage between IIS and Kestrel.(image)



Dragging and Dropping Images and Files into the Web Browser Control

Fri, 10 Mar 2017 09:23:34 GMT

Dragging content into the Web Browser control and capturing the content dropped can be tricky. The Web Browser Control is based on Internet Explorer and is actually an ActiveX control hosted inside of a container and because of that is difficult to deal with. In this post I describe how you can get around this issue and still capture images and files dropped on the control and handle the drop operations.(image)



Debugging the Web Browser Control with FireBug

Wed, 08 Mar 2017 10:09:31 GMT

If you need to debug JavaScript code or layout issues in a Web Browser control inside of a Windows desktop application, you've probably found that the experience sucks. Although Internet Explorer on which the control is based suppports rich developer tools, those are not available in the Web Browser control. Enter an oldie but goodie: FireBug which is an embeddable Console implementation that provides a lot of the features that you find in modern browser developer tools and with a couple of lines of html you can add this debugger into your application.(image)



Getting JavaScript Properties for Object Maps by Index or Name

Sat, 04 Mar 2017 21:59:11 GMT

Getting value out of maps that are treated like collections is always something I have to remind myself how to do properly. In this post I look at JavaScript object iteration and picking out values from a JavaScript object by property name or index.(image)



Video Rendering Issues for WPF Windows

Tue, 14 Feb 2017 00:57:23 GMT

Recently I ran into a few reports of black screen of death rendering of Markdown Monster when starting up from a very few users of the application. They reported the screen just shows black, while actually being responsive to moving and showing menus etc. Also moving to another screen often fixes the problem. It turns out this is a hardware related issue with WPF with certain video hardware/monitor combinations. In this post I describe the problem and the workaround to get the application to render properly even on compromised hardware.(image)



Empty SoapActions in ASMX Web Services

Sun, 12 Feb 2017 19:12:01 GMT

Recently I had to deal with an ASMX Web Service that was receiving empty SoapActions from the client. ASMX doesn't like that, but luckily there's an easy work to strip out the errant Soap header.(image)



Creating a portable and embedded Chocolatey Package

Sun, 29 Jan 2017 21:05:40 GMT

Chocolatey is an awesome tool to install software. As a publisher you have a lot of choices of how to create packages and in this post I describe the two packages that I use with Markdown Monster, which is a full downloaded installer package and a fully self contained embedded portable package. Here I cover the basics of Chocolatey package creation and some of the steps required to create a portable package from a full installation and some of the challenges you might run into along the way.(image)



Adding Files to Visual Studio Projects

Wed, 25 Jan 2017 19:35:31 GMT

Visual Studio has a boat load of ways to add new files to a project and various extensions and tools provide even more ways to do the same. Even so the experience to add new files to a project in Visual Studio is one of the most tedious tasks. Here's what bugs me and how I try to work around the verbosity of it all.(image)



New CODE Magazine Article: Getting down to Business with ASP.NET Core

Thu, 12 Jan 2017 20:19:27 GMT

The latest issue of CODE magazine features my `Getting down to Business with ASP.NET` Core article as the cover article. The article focuses on building an ASP.NET Core backend for an Angular 2 front application, covering all aspects of separating business and Web app logic, dealing with EF Core data access in related tables, CORS to be able to run across domains and simple authentication in a client centric REST service application. Check it out.(image)



Faking out the .NET Runtime Version

Tue, 10 Jan 2017 07:04:01 GMT

I've been struggling with DPI Scaling issues in WPF in Markdown Monster and .NET 4.6.2 has a few fixes that address the problems I've been working on. However, requiring 4.6.2 is a problem due to lowish adoption rates and skittishness about installing new versions of .NET. In this post I show a little hack that allows me to compile my app to .NET 4.6.2 but don't require user to have that version installed so those that have it can take advantage of the updates.(image)



Back to Basics: String Interpolation in C#

Tue, 27 Dec 2016 08:12:59 GMT

String Interpolation provides string templating for string literals in C#. Rather than using string.Format you can use string interpolation to produce much more readable code that embeds expression values directly into string literals rather than escaping numeric arguments as you do with string.Format(). In this post I look at how string interpolation works, what the compiler does under the covers and some common use cases where it makes life easier.(image)



Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control

Fri, 23 Dec 2016 09:14:52 GMT

Recently while working on Markdown Monster I ran into some odd crashes and behaviors when interacting with the Web Browser control in this WPF application. It turns out that some of these inconsistent behaviors are apparently caused by running hte application in 64 bit mode. Switching to 32 bit mode has made the application and Web Browser interaction much more responsive and has stopped the nagging unexplainable crashes. In this post I look at 32 and 64 bit applications in .NET and outline some of the issues I ran into and how I fixed the problem by switching to building a 32 bit app.(image)