Programming: .NET Framework

The old, well-loved, well-worn Windows-only version of .NET

Posted At: 9/8/2022 12:15:12 PM
Posted By: Comfortably Anonymous
Viewed: 1381 times
0 Dislikes: 0
Had some big JSON returned from a Web API project I was developing, Swagger was taking FOREVER (More than 20 minutes!) to display the returned data.So I got looking into what I could do to increase the speed. Found some good settings that massively improve the rendering speed. The main fix is to disable Syntax Highlighting, but the other settings are handy as well.Depending on your app, open either Startup.cs or Program.cs, look for the part that has app.UseSwaggerUI() and expand it as follows:app.UseSwaggerUI(c =>{ // Expand details shown from default setting c.DefaultModelExpandDepth(2); // Smaller display onscreen c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None); // Display the example JSON by default c.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Example); // Make it so you don't have to keep clicking "Try It Now" to use a WebApi method. c.EnableTryItOutByDefault(); // Disable highlighting as it really bogs down with large JSON loads. c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false);});
Posted At: 1/26/2022 10:48:50 AM
Posted By: Comfortably Anonymous
Viewed: 935 times
0 Dislikes: 0
There are many reasons you may need to know/use/track the IP that an incoming request came from. Turns out it's not too hard, but a little sloppy, would think there's a better way to get it than inspecting server variables by name, but here we are.First off, there are two places it can appear, so they need to be checked in order. The first is "HTTP_X_FORWARDED_FOR", which will be filled in if something (such as a proxy server or a NAT) is forwarding the request from the original requestor. If there's nothing there, then secondly we need to check "REMOTE_ADDR". If there's no forwarder in place, then you get the actual requesting IP - but if there is a forwarder, then REMOTE_ADDR will contain the IP of the forwarder, thus why we have to do this two-step lookup.Here's some example C# code for doing just that:public string GetRequestingIp()   {       // First, see if the request came in via a forwarder. (If so, then use the address in this field.)     var ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];            if (string.IsNullOrEmpty(ip)) // We didn't get the request via a forwarder, so get the actual remote address.     {           ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];       }          // Return whichever address was found.     return ip;   }
Posted At: 12/1/2021 3:59:39 PM
Posted By: Comfortably Anonymous
Viewed: 758 times
0 Dislikes: 0
Need to upgrade legacy .NET Framework apps to .NET Core? This article goes over the big changes between the old and the new along with examples of commonly encountered issues and ways to mitigate them. Also a link to an entire free eBook (Porting existing ASP.NET Apps to .NET Core) [PDF] as well.https://docs.microsoft.com/en-us/aspnet/core/migration/proper-to-2x/?view=aspnetcore-6.0
Posted At: 10/25/2021 12:42:47 PM
Posted By: Comfortably Anonymous
Viewed: 714 times
0 Dislikes: 0
Developing containerized microservice applications means you are building multi-container applications. However, a multi-container application could also be simpler—for example, a three-tier application—and might not be built using a microservice architecture.Designing and Developing Multi Container and Microservice Based .NET Applications
Posted At: 9/20/2021 10:30:48 AM
Posted By: Comfortably Anonymous
Viewed: 869 times
0 Dislikes: 0
Beginner's Series to: Blazor | Channel 9 (msdn.com)
Posted At: 8/31/2021 12:12:53 AM
Posted By: Comfortably Anonymous
Viewed: 834 times
0 Dislikes: 0
Cool, this is an awesome feature! However, I've been using "real' visual studio for almost 20 years. And really struggling with the lack of anything visual with it. I keep trying to understand what people mean when they say it's not an ide. I'm sorta old. I grew up in the dos days. [Technically C64 days].) I'm used to typing in complex commands. I once wrote a bbs from scratch in turbo pascal. I'm used to typing in complex commands. In the old days, (you'd grab yer fiddle and dosey doe. Er, umm...)I learned a pure text way of life. But I learned visual studio VISUALLY. Maybe I'm lame but I'm used to visual studio doing a lot of boilerplate for me. Stuff that would take a few seconds of submenu clicking, then on to the actual task I need to complete. Instead with vscore I spend all this time searching, reading, trying, getting frustrated, then going back to regular vs 2019 pro and getting to work. A good editor, but it's about Damn time for a Linux version of the real visual studio!// wdf did i just read?// yes, yes you did. Now explain yourself you damned human, muahaha// wdfdijr?Help
Posted At: 7/9/2021 11:11:52 AM
Posted By: Comfortably Anonymous
Viewed: 937 times
0 Dislikes: 0
Why something like this isn't built into .NET, I have no idea. But several places I've worked at have had variations on this to make development easier. So here's my implementation of it:using System.Collections.Generic;using System.Linq;namespace [ProjectName].ExtensionMethods{   public static class GenericExtensions   {      ///       /// Indicates if the source value is contained in the passed list.      ///       /// Source value we are looking for in the list.      /// List of values to search.      /// bool      public static bool IsContainedIn(this T sourceValue, IEnumerable list)      {         return list.Contains(sourceValue);      }      ///       /// Indicates if the source value is contained in the passed params.      ///       ///       /// Source value we are looking for in the list      /// Param array of values to search.      /// bool      public static bool IsContainedIn(this T sourceValue, params T[] list)      {         return list.Contains(sourceValue);      }   }}Usage examples:using ContainedTest.ExtensionMethods;using System;using System.Collections.Generic; namespace ContainedTest{   class Program   {      static void Main()      {         ExampleWithList();         ExampleWithParams();          Console.Write("Press Enter");         Console.ReadLine();      }       private static void ExampleWithList()      {         var sourceValue = 3;         var valueList = new List { 1, 2, 3, 4, 5, 6, 7, 8 };          Console.WriteLine("Example with List:");          Console.WriteLine($"Is 3 contained in value list: {sourceValue.IsContainedIn(valueList)}");         Console.WriteLine($"Is 22 contained in value list: {22.IsContainedIn(valueList)}");         Console.WriteLine($"Is 3 contained in inline-supplied list: {sourceValue.IsContainedIn(new List { 2, 3, 7, 22 })}");          Console.WriteLine();      }       private static void ExampleWithParams()      {         Console.WriteLine("Example with Params:");          var sourceValue = 3;         Console.WriteLine($"Is 3 contained in param array: {sourceValue.IsContainedIn(1, 3, 5, 7, 9)}");         Console.WriteLine($"Is 22 contained in param array: {22.IsContainedIn(1, 3, 5, 7, 9)}");          Console.WriteLine();      }   }}Enjoy!
Posted At: 4/7/2021 5:13:58 PM
Posted By: Comfortably Anonymous
Viewed: 1153 times
0 Dislikes: 0
So SQL Server Management Studio has a Dark Theme included. But it's still not fully endorsed by Microsoft, so it's weirdly hidden.The following PowerShell script will unlock the Dark Theme in SSMS 18.x. (Make sure and run PowerShell as an Administrator, or this won't work.)powershell -Command "(gc 'C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\ssms.pkgundef') -replace '\[\`$RootKey\`$\\Themes\\{1ded0138-47ce-435e-84ef-9ec1f439b749}\]', '//[`$RootKey`$\Themes\{1ded0138-47ce-435e-84ef-9ec1f439b749}]' | Out-File 'C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\ssms.pkgundef'"Then when that gets done, open up SSMS again, select Tools, Options, then Environment/General and now there's a "Dark" entry in the Color Theme list. Pick it, hit OK, and you're golden. (Well, not golden, more of a darker gray.)
Posted At: 3/28/2021 1:39:29 AM
Posted By: Comfortably Anonymous
Viewed: 1240 times
0 Dislikes: 0
Rock, Paper, Scissors, Lizard, Spock is the geek version of the classic Rock, Paper, Scissors game. Rock, Paper, Scissors, Lizard, Spock is created by Sam Kass and Karen Bryla.The Rock, Paper, Scissors, Lizard, Spock - Sample Application shows a multilanguage application built with Visual Studio and Visual Studio Code, deployed with GitHub Actions and running on Azure Kubernetes Service (AKS). The sample application also uses Machine Learning and Azure Cognitive Services (Custom Vision API). Languages used in this application include .NET, Node.js, Python, Java, and PHP. Source Code for RPSLS on GitHubPlay the game hosted on Azure: https://RockPaperScissorsLizardSpock.devThe path to .NET 5 and Blazor WebAssembly with some RPSLS fun sprinkled inWith the recent release of .NET 5 at .NET Conf 2020, users saw first-hand how to take advantage of the latest web technology using .NET. One extremely interesting announcement was the new release of Blazor WebAssembly. Blazor lets you build interactive web UI wuth C# instead of JavaScript. Blazor WebAssembly allows users to build a completely isolated application entirely in C# that can run in nearly every web environment, including environments that only support static sites (think only HTML, CSS and Javascript). Blazor WebAssembly does this by compiling all C# code needed to run your application (your code and .NET libraries) into native code that will execute on the browser, not a server somewhere. This is valuable in scenarios when your app needs to run offline, or completely decoupled from a server, and your app only needs a server if it requests data outside ...
Posted At: 4/7/2020 3:33:05 PM
Posted By: Comfortably Anonymous
Viewed: 1316 times
0 Dislikes: 0
JSON has a weird text format. Here's how to easily convert to it from a C# DateTime:public string GetJSONFromUserDateTime(DateTime dt){ dt = dt.ToUniversalTime(); string jsonDateTime = string.Empty; if (dt != null) { JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; jsonDateTime = JsonConvert.SerializeObject(dt, microsoftDateFormatSettings); jsonDateTime = jsonDateTime.Replace("\"\\/Date(", "").Replace(")\\/\"", ""); } return jsonDateTime;}