Recent Posts

SEO Urls

SEO Urls in ASP.NET Core sind extrem simpel, alles was man braucht ist eine Route an der Action. Bei Interesse kann man die URL auch auswerten, muss man aber nicht. ``` C# [Route("/Blog/ViewPosting/{id}")] [Route("/Blog/ViewPosting/{id}/{title}")] public IActionResult ViewPosting(int id) { [...] return View(posting); } ``` ... <a href="/Blog/ViewPosting/19/seo-urls">(Weiterlesen)</a>

12/21/2022 5:16:40 PM by Chris 665

Caching in ASP.NET Core

Quellen: * https://andrewlock.net/adding-cache-control-headers-to-static-files-in-asp-net-core/ * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0 * https://stackoverflow.com/questions/37706370/how-to-cache-css-js-or-images-files-to-asp-net-core Heute hab ich ein wenig Caching in den Blog eingebaut, als Inspiration hatte ich die Links oben. Zuerst wird die Program.cs angepasst ``` csharp var builder = WebApplication.CreateBuilder(args); builder.Services.AddResponseCaching(); var app = builder.Build(); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { string path = ctx.File.Name.ToLower(); if (path.EndsWith(".css") || path.EndsWith(".js") || path.EndsWith(".gif") || path.EndsWith(".jpg") || path.EndsWith(".png") || path.EndsWith(".ico") || path.EndsWith(".woff2") || path.Contains("/blog/getimage/")) { var maxAge = new TimeSpan(7, 0, 0, 0); ctx.Context.Response.Headers.Append("Cache-Control", "max-age=" + maxAge.TotalSeconds.ToString("0")); } else { //Request for views fall here. ctx.Context.Response.Headers.Append("Cache-Control", "no-cache"); ctx.Context.Response.Headers.Append("Cache-Control", "private, no-store"); } } }); ``` Und nun pass wir wir noch die GetImage Funktion an ``` csha ``` ... <a href="/Blog/ViewPosting/17/caching-in-asp.net-core">(Weiterlesen)</a>

12/21/2022 5:09:18 PM by Chris 885

Autocomplete Box mit JavaScript und C# in MVC

Der JS und HTML Code ist von hier übernommen: https://www.codexworld.com/autocomplete-textbox-multiple-values-jquery-php-mysql/ Erstmal die Vorlage ``` HTML <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> ``` ``` JS <script> $(function() { function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } $( "#skills" ).bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB && $( this ).autocomplete( "instance" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ minLength: 1, source: function( request, response ) { // delegate back to autocomplete, but extract the last term // $.getJSON("skills.php", { term : extractLast( request.term )},response); //orginal .getJSON("/Blog/Tags", { term : extractLast( request.term )},response); //meine anpassung }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { var terms = split( this.value ); // remove the current input terms.pop(); // add the selected item ``` ... <a href="/Blog/ViewPosting/9/autocomplete-box-mit-javascript-und-c#-in-mvc">(Weiterlesen)</a>

7/8/2022 10:22:21 PM by Chris 930

markdown-it and highlightjs in MVC APSNetCore .NET6.0

markdown-it mit highlight.js in ASP.NET MVC als reines JavaScript https://highlightjs.org/ https://markdown-it.github.io/ C# Code für das Posting ``` C# @section Scripts{ <script type="text/javascript" > $(document).ready(function() { postingsMD = {}; @foreach(var posting in Model) { @Html.Raw("postingsMD[" + posting.Id + "] = $(\'.blog-content" + posting.Id + "').html().replace(/&amp;/g, \"&\").replace(/&lt;/g, \"<\").replace(/&gt;/g, \">\").replace(/&quot;/g, \"\\\"\").replace(/&#x27;/g, \"'\");") } var md = window.markdownit({ html: true, linkify: true, typographer: true }); $.map( postingsMD, function( val, i ) { $('.blog-content' + i).html(md.render(val)) }); hljs.highlightAll(); }); </script> } <p class="@Html.Raw("blog-content" + posting.Id)">@posting.Text</p> ``` HTML Code im Header ``` HTML <link href="/lib/highlightjs/styles/default.min.css" rel="stylesheet" > ``` HTML Code am Ende ``` HTML <script src="/js/jquery.min.js"></script> <script src="/lib/markdown-it-13.0.1/markdown-it.js"></script> <script src="/lib/highlightjs/highlight.min.js"></script> @await RenderSectionAsync("Scripts", required: false) </body> </html> ``` ... <a href="/Blog/ViewPosting/7/markdown-it-and-highlightjs-in-mvc-apsnetcore-.net6.0">(Weiterlesen)</a>

7/6/2022 10:22:21 PM by Chris 1071


Scroll to Top