Recent Comments



Arun
Thursday

re: Serving URLs with File Extensions in an ASP.NET MVC Application

Nice Article. I am trying to use the method you mentioned here in one of my project. Instead of xml files, in my case I would like to serve .pdf files in MVC pipeline. I have created a handler like below

And I have created a folder named CommonFiles inside the route directory and copied few pdf files there for testing. But the issue is when ever I try to access those files I am getting an internal server error , Its not even going through the MVC pipeline. If I just give a path which is not exists with a .pdf then its trying to go via MVC pipeline. Can you please hep me here ?


Rick Strahl
Thursday

re: PC and Mac with single Mouse and Keyboard Setup on Dual 4k Screens

I have a custom made desk - I bought a standup desk frame and then put my own desktop from the same planks used in the Bamboo flooring as the desk top. Size wise it's a little wider than standard size but not much. Monitor space isn't a problem.

However, I ended up movable arms for the monitors (https://amzn.to/2Kz4T4m which work great) and also got rid of the 40" screen and replaced it with another 32" (same as the other). I'm actually much happier with the 32" screen as my over visibility is much better and I can be closer. After initial discomfort for 'downsizing' size change, now the smaller size seems perfect.


Greg
Thursday

re: PC and Mac with single Mouse and Keyboard Setup on Dual 4k Screens

Hi Rick,

Great post, thank you for sharing your experience. I've been looking for a solution like this. My searches usually end with "virtualization" hits vs running both OS's side by side. I'm currently using one 40" monitor and juggling wires between systems, so I'm excited to try this solution. Silly question... but how long and deep is your desk and do you feel like you have "enough" space? I'm ready to hit the buy button on another monitor, but wondering if I need to include a new desk in the budget.

Thanks again,

Greg


Morten79
Tuesday

re: Deleting Problem Folders and Files on Windows: Could not find this Item Error

OMG you're such a nice man. After digging and searching for over two hours I finally found your blog article. I finally got rid of that mysterious folder and I thank you many times. I was nearly getting crazy 😄


Rick Strahl
Monday

re: Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1

@Byron - the runtimes are updated supposedly on a 6 week cycle, but they're late with the latest updates it seems.

The runtimes are always available, but latest features are only available via Canary builds and any runtime install overrides the Canary build Runtimes. So yeah, it's all confusing as hell.


Byron Adams
January 17, 2021

re: Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1

Nice writeup. From what I understand as of Nov. 20,2020, version 1.0.664.37 is done and does not need the Canary build. However, the development continues, that's why you see new Previews.


Rick Strahl
January 15, 2021

re: Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1

@Cory - Unclear at this point. I've raised various issues around this and I haven't gotten a clear answer. I think they are still trying to figure out how the runtimes will eventually be distributed, but in the near term they have to be distributed explicitly as described in the post unfortunately.

According to the info I've gotten they won't be shipping with Edge because of size (imagine that) as it essentially doubles the install size. The discussion mentioned potentially as part of Windows updates though, but then you run the risk of out of date runtimes (which would also be a problem with Edge installs although less likely since those auto-updated frequently).


Cory
January 15, 2021

re: Taking the new Chromium WebView2 Control for a Spin in .NET - Part 1

I presume the WebView2 control is only a separate runtime install during preview...it will eventually be installed with Edge once it's released, right?


Rick Strahl
January 11, 2021

re: Creating Custom .NET Project Types with .NET CLI Project Templates

@Nick - You can pass parameters, but how you handle them is up to you to do decide. There's an example in the template I show above. But it will only work if you use the command line, not in Visual Studio unless you build a more complete template project extension.


Nick
January 11, 2021

re: Creating Custom .NET Project Types with .NET CLI Project Templates

Thanks for the article. Do you know if there's a way to pass flags to control what the template includes? For example choosing between a range of unit test frameworks


Rick Strahl
January 09, 2021

re: Window Activation Headaches in WPF

@Joel - that sounds promising, but I didn't try it out. In my case it's the same application - ie. Markdown Monster invoking another instance of Markdown Monster - to launch the second instance and I would have no way to notify the first instance of the second instance before it's already calling into the old one (maybe it would work as part of the activation logic). That's a bit twisted though and be a pain to figure out a few years down the road 😄


Ioannis Kyriakidis
January 06, 2021

re: Blank Zero Values in .NET Number Format Strings

I didn't know about this feature either. Now it comes to my mind the cases that I could use it 😃. Nice and detailed post, Thanks


Rick Strahl
January 06, 2021

re: Windows Authentication and Account Caching on Web Browser Auto-Logins

@Tyler - I don't think so. Server side applications can only sent HTTP responses and the browser has to decide what to do with those. Those behaviors are therefore determined by browsers not the server.

AFAIK, the options described in this post are the ones you can tweak in regards to Windows Authentication but I don't think you can specify whether auto-login or explict login occurs.


Tyler
January 06, 2021

re: Windows Authentication and Account Caching on Web Browser Auto-Logins

Hello, I have a similar setup on a site that i am building and i would like for it to prompt for login everytime, regardless of browser. Is there a way to do this at the application level instead of having to configure individual browsers? I cannot find anything searching google for a solution

Thanks in advance

Tyler


Sjoerd
January 05, 2021

re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

Great article.

About your comment: "move to a custom account that matches the actual rights required by the application".

I'm searching for the least amount of privileges needed for an specific account to run an asp.net core 2.1 application. However i can't seem to find information about this. Any links/suggestions?


Rick Strahl
December 31, 2020

re: ASP.NET Core and CORS Gotchas

@Brian - Uh, the very first example in this post does just that?


Brian
December 31, 2020

re: ASP.NET Core and CORS Gotchas

For anyone struggling with the pre-flight CORS error not working, I found the answer on another blog. Set it to allow any headers (and any methods if you wish).

services.AddCors(options =>
  {options.AddPolicy(name: MyAllowSpecificOrigins,
  builder =>
  {
    builder.WithOrigins("http://localhost:3000")
    .AllowAnyHeader()
    .AllowAnyMethod();
  });
});

The site is here: https://www.cognizantsoftvision.com/blog/cross-origin-resource-sharing-and-asp-net-core-3-1/


Bineesh
December 27, 2020

re: Empty SoapActions in ASMX Web Services

I came here for SOAP but i was so surprised to see a real & authentic Soap of Kerala, the Chandrika. Do you really bathe with it ?


Scott Beam
December 21, 2020

re: Back to Basics: Rewriting a URL in ASP.NET Core

i spent 2 days on trying to redirect subdomains in core 3.1 digging thru posts on stackexchange and then found this post and had it working within 5 minutes. thanks huge. donation on the way


Nick
December 18, 2020

re: Which .NET Core Runtime Download do you need?

Good stuff. Nice presentation. Rick, I have a new application windows 2019 server that's been running two Blazor WASM client/server solutions under aspnet core 3.1 (hosting bundle). I've since updated dev solutions to use aspnet core version 5. Is it ok to leave the 3.1 server hosting bundle, or would you recommend I uninstall 3.1 first? Many thanks


CJ
December 12, 2020

re: Deleting Problem Folders and Files on Windows: Could not find this Item Error

I have tried SO Many things and None of them worked until I found your article.

Pesky files Gone! Thank you!


John
December 09, 2020

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

Rick, Thanks again for another easy and informative post. Don't want to clutter your comments section but thanks! will paypal you some monies for some new board wax :p


Rick Strahl
December 04, 2020

re: Watch out for .NET Core Runtime Bitness for IIS Installs

@Mac - it doesn't matter if you have it enabled, it'll work with Managed code enabled. In fact, you can run both managed and one .NET Core app in a shared App Pool (I actually did that by accident) and it works.

The reason it's recommended to not have it on is that if on the managed pipeline is loaded which adds a small amount overhead and memory usage. If you're purely running Core there's no need to have that on.


Mac
December 04, 2020

re: Watch out for .NET Core Runtime Bitness for IIS Installs

Probably minor but in your IIS app pool settings I think ANCM2's recommended .NET CLR Version should be "No Managed Code"... which I only noticed because I was running one dev box with the default ".NET 4.0" recently, too -- I didn't see any difference but I'm pretty sure I read it somewhere recently in the docs.


Peter
December 01, 2020

re: Slow Connections with Sql Server

thanks a lot for the input, i had 6 seconds for the connection and with the activation of TCP/IP i'm down to 0.01


chaami
November 27, 2020

re: Accessing Configuration in .NET Core Test Projects

Hi Rick,
Thank you very much for this post, it gave me the courage to tinker around it 😉
Have you tried removing the need of using the outputPath variable and directly defining it to point the tested project appsettings with:

string outputPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(KavaDocsConfiguration).Location);

This should allow you to avoid having to copy the appsettings.*.json files.
Even if they quickly become stable, it's still a pain to have duplicated info.

Hope this helps, thanks again !
👋


Luis Abreu
November 26, 2020

re: Upgrading several of my Applications and Libraries to .NET 5.0

Not as lucky here... since binary serialization is obsolete, I chose to rewrite that part (that was easy, but had also to migrate thousands of entries from binary to json) and had also some issues with the DateTime breaking change... but overall, no biggies


IvanP
November 26, 2020

re: Bypassing IIS Error Messages in ASP.NET

Hello, please fix the small letter 't' in

<httpErrors existingResponse="Passthrough" />

Should be

<httpErrors existingResponse="PassThrough" />

People who copy/paste your config line have issues with loading the site because of this type

Thanks


Mat Polutta
November 25, 2020

re: Upgrading several of my Applications and Libraries to .NET 5.0

Came here to read about pain with .Net Upgrade, but got nothing but good news. Bonus: Angular upgrade from 9 to 11. I have an Angular Dynamics CRM toolkit that is at 9 and was thinking of upgrading to 11, but dreading the pain (last upgrade to 9 went smoothly, but remembrance of past headaches was holding me back). I'll try sometime today or over the Thanksgiving holiday.


Allan
November 25, 2020

re: Use IIS Application Initialization for keeping ASP.NET Apps alive

Old post but I recently ran across it and also had the issue with the site not restarting on deploy. Looking around for different solutions I found that you can actually restart the app pool using webdeploy as well:

msdeploy.exe -verb:sync -source:recycleApp -dest:recycleApp="MyAppPool",recycleMode="RecycleAppPool",UserName='Administrator',AuthType='Basic',ComputerName="https://myserver:8172/msdeploy.axd?site=MyApp",Password=mypassword -allowUntrusted

Msdeploy is installed by visual studio at C:\Program Files (x86)\IIS\Microsoft Web Deploy V3

Perhaps someone will find this useful 😃


Rick Strahl
November 24, 2020

re: Null API Responses and HTTP 204 Results in ASP.NET Core

@Igor - if you use IActionResult Swagger can't determine the type of the data you're returning. It works but the type information won't be available.


jp2code
November 20, 2020

re: Excluding Files and Folders in Visual Studio Web Site Project

I see how to remove a file, but how do I remove a FOLDER? We have a TypeScript folder in our project that has 10 files and 14 Subfolders. Each subfolder has files and folders as well. If I could just tell VS2019 to exclude Folder "TS" from the build, that would save LOTS of time!


Igor
November 20, 2020

re: Null API Responses and HTTP 204 Results in ASP.NET Core

Hey Rick, thanks for the article! In one of your comments you mention issues with IActionResponse when using Swagger ("That has consequences like not being able to easily use Swagger.") Could you elaborate? I use both in my APIs and was curious about the issues you're running into. Thanks!


Michael
November 18, 2020

re: Using the brightness() CSS Filter to generically highlight Content

I saw a new CSS feature supported in Firefox 83 and thought it might be interesting. It is a conic gradient:

Firefox 83 adds support for conic gradients in CSS, helping colors to smoothly transition as you spin around the center, rather than as you progress outward from the center.

I assume you can punch out the middle and make an animated hourglass with it.

Firefox 83.0, See All New Features, Updates and Fixes


Ben
November 17, 2020

re: Fixing Visual Studio Intellisense Errors

Just in case someone faces intellisense issues after migrating a project to VS2019 or after a VS update. See here.

Analyze > Build and Suppress Active Issues is a very helpful thing 😉


Paul
November 12, 2020

re: Web Browser Control & Specifying the IE Version

Hi Rick,

Hello from Canada.

WOW! Thanks for this. In one of our VFP9 products we use a third party HTML control to display maps. We have struggled with this problem for years (IE compatibility mode warnings).Your suggested solution solved all our issues. Finally! Thanks so much!


Alois Kraus
November 12, 2020

re: A .NET Color Console Helper

This is a great class! I have added two things.

  1. Some people use custom background colors which make custom colors unreadable
         /// <summary>
        /// For guys who do not like the color scheme make it possible to turn it off
        /// </summary>
        public static bool EnableColor
        {
            get; set;
        } = true;

and then in the various places added the check:

        public static void WriteLine(string text, ConsoleColor? color = null)
        {
            if (color.HasValue && EnableColor)
  1. When pressing Ctrl-C/Break switch back to the initial color (most of the time) to prevent cluttering up the console output after our program has exited
      /// <summary>
       /// Default color 
       /// </summary>
       static readonly System.ConsoleColor InitialForeColor = System.Console.ForegroundColor;

       static ColorConsole()
       {
           CtrlCHandler.Instance.Register(Console_CancelKeyPress);
       }

       private static void Console_CancelKeyPress()
       {
           EnableColor = false; // other threads might still be printing after we have reset the console color
           Console.ForegroundColor = InitialForeColor;
       }

Luke O'Brien
November 12, 2020

re: Adding Additional Mime Mappings to the Static File Provider

Thanks Rick, this is really helpful and provided the solution to my problem, actually I read your blog quite a lot and I have found many solutions to problems I come accross on your blog!
I am using Blazor, I have a UI project and a Api project, I am publishing my UI project to the wwwroot of another "Publish" project and serving the Blazor dlls as static files.

One knew puzzle. I noticed that the new .Net 5 is generating .br and .gz files.
How do we check the accept-encoding header and return the .gz version of the file if it exists?
I tried the following but the file.context is read only:

            app.UseStaticFiles(new StaticFileOptions
            {
                // add the mimemappings
                ContentTypeProvider = extensionProvider,
                OnPrepareResponse = content =>
                {
                    if (content.Context.Request.Headers.ContainsKey("accept-encoding") &&
                        content.Context.Request.Headers["accept-encoding"].Contains("gzip"))
                    {
                        var path = content.File.PhysicalPath;
                        path += ".gz";
                        if (File.Exists(path))
                        {
                            content.File = new FileInfo(path);
                        }

                    }
                }
            });

Rick Strahl
November 06, 2020

re: Building a Live Reload Middleware Component for ASP.NET Core

@William - CSS changes will not immediately show - you need to hard reload the page once before CSS changes show in Chromium browsers. Due to the cache logic in Chromium (and other browsers too I think). After the one hard refresh, CSS changes will show up as you make them... weird behavior but apparently this is by design.


William
November 06, 2020

re: Building a Live Reload Middleware Component for ASP.NET Core

Update to previous comment:

I change my folder to monitor from

"FolderToMonitor": "~/../"

to

"FolderToMonitor": "~/.."

I also restarted my browser due to any update so one of the two fixed it.


CB
November 02, 2020

re: Dealing with Anti-Virus False Positives

When you got your signature certificate, what personal information did you provide? I would like to use my company information only, and not my personal information.


Annie
November 02, 2020

re: HttpWebRequest and GZip Http Responses

Hi Rick,

Can I use it in my WCF service the client need the response to be gzip encoded and should I place the HttpCompression code after each response (multiple scenarios for failure and success) or just one time before creating the response and sending it.

response = new Basic_Response { code = "0", message = "Auth Failed", data= null, success= true };

                HttpResponse Response = HttpContext.Current.Response;
                string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
                if (AcceptEncoding.Contains("gzip"))
                {
                    Response.Filter = new System.IO.Compression.GZipStream(Response.Filter, 
                 System.IO.Compression.CompressionMode.Compress);
                    Response.AppendHeader("Content-Encoding", "gzip");
                }

Chris Marisic
October 30, 2020

re: Use Powershell to bind SSL Certificates to an IIS Host Header Site

Following up to Dave's answer, this can be one-lined and not require any variables at all:

(Get-WebBinding -Name "My Api" -Port 443 -Protocol "https" -HostHeader "api.my.com")
.AddSslCertificate("SSL_THUMBPRINT_HERE", "my")

The last parameter "my" will resolve to the certificate store for the local computer for the Personal\Certificates folder [typical webserver SSL installation location]. You can grab the thumbprint value by inspecting the certificate in a browser, certmanager snapin, or alternatively you can use other commands on this post/comments to get the cert via powershell and access the thumbprint as a property of it.


Daniel Rose
October 29, 2020

re: Static Constructor Failures and Declaration Order

I saw that almost immediately, but the reason being that I got burned by something similar before.

If you use WPF's DependencyPropertyKey, it needs to be initialized before the corresponding DependencyProperty. ReSharper used to rearrange that, which caused similar errors during runtime (IIRC I filed a bug for that).


Rick Strahl
October 28, 2020

re: Creating Custom .NET Project Types with .NET CLI Project Templates

@Ignat - not that I know of, and frankly I think that would be a terrible idea as that would be an invitation for malicious code to execute.

Since they are delivered as NuGet packages, you're limited to the NuGet operation which AFAIK doesn't include code execution of any kind.

If you need templates that execute code you likely need to build for Visual Studio and use a VSIX.


Ignat Andrei
October 28, 2020

re: Creating Custom .NET Project Types with .NET CLI Project Templates

Just asking : could we run custom code in our template after dotnet new is doing his job ?


Laurens
October 23, 2020

re: Flexbox Containers, PRE tags and managing Overflow

Found your post through https://drailing.net/2018/04/css-quicky-fixing-flexbox-width-with-pre-tags/.

I stumbled upon the breakout problem of pre inside a parent which was itself part of a display: grid rendering using auto in grid-template-columns. Applying min-width: 0 to the parent solved the issue. So it seems the solution and underlying implementations relate to flexbox as well as to grid layouts - in Chrome at least.


WizX20
October 22, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

For anyone running into this exception after changing DEBUG settings in the project properties. have a look at issue 16805

In short

  • Close the application and VS
  • Go to the solution root and delete the entire .vs folder
  • Done

Rick
October 21, 2020

re: Mirror your iOS Device Screen on Windows with the free 5KPlayer

@Kimon - I'm pretty sure that Bonjour is required in order to sync through iTunes. I can't be 100% sure because I may have had a pre-store version of iTunes installed, but I didn't install anything special to make either iTunes sync or 5k player work.

You should check and see whether the service is installed and perhaps not enabled or started.