Skip to main content
Home  › ... 2sxc Apps

Basic Tutorials

Tutorial Home

Safely Linking URLs with Umlauts and similar

👈 this image is called göögle plus.png - which must be encoded to g%C3%B6%C3%B6gle%20plus.png


      @{
        var path = App.Path + "/basics/assets/urls/";
        var exampleImgName = "göögle plus.png";
        var resizeParameters = "?w=100";
        var safeUrl = Tags.SafeUrl(path + exampleImgName + resizeParameters);
      }
      <img loading="lazy" src='@safeUrl' id="demo-logo">
    

Sometimes you have files with unexpected characters - like umlauts or spaces. The best way to encode this is using Tags.SafeUrl(...) from RazorBlade, or Uri.EscapeUriString(...) from .net.

Important notes

  • Two characters won't resolve properly on a standard web server: + and %. There are ways to work around this, but we would avoid them at all cost.
  • Other characters like spaces, umlauts (öäè) etc. are no problem.
  • You may also find suggestions to use Server.UrlEcode(...). This often doesn't work!
  • Remember to add @using System to make this fly

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->
@using ToSic.Razor.Blade;
@using System;
Safely Linking URLs with Umlauts and... <!-- unimportant stuff, hidden -->

<!-- unimportant stuff, hidden -->