Recent Comments



Rick Strahl
Yesterday

re: Using .NET Core Tools to Create Reusable and Shareable Tools & Apps

@Kathleen - thanks for the extra information. I was focusing on the global tool aspect so didn't spend much time on this already long article talking about local install or CI specific builds. Probably should add a note to that effect at least.

Love these tools - been a big help in using some stuff, especially the LiveReloadServer I mention in the examples which I use all the time as a dotnet tool.


Kathleen Dollard
Wednesday

re: Using .NET Core Tools to Create Reusable and Shareable Tools & Apps

Great article!!!

You are correct on the search, but we are finally able to fix it in .NET 5.0!!!! Look for dotnet tool search <searchString> in the Preview or final release πŸ˜ƒ

We suggest that you target as low as possible, and if you don't think you'll do anything risky, have it roll forward forever! Shall I look up the project file syntax for that? Here's a work item that covers the details and has a link to the spec.

I think it's simpler to prefix your package ID with your own brand, or with no brand. I don't think the dotnet is helpful here, but it does show that they don't need to match. The Package ID must be unique on NuGet. The commandName must be unique on the box.

You covered just about

About the only thing you didn't cover is that there are 3 installation methods people can use. Global is great when a single version works across your machine. Local is designed for simplifying repo setup and for specifying tool version per repo. Tool-path is when you want to put it in a specific place, rather than calling from the global location. This is good for CI, for example. Microsoft docs has a great article.

Thanks again for the super great article! And wishing you much wind!

(I'm the PM for .NET (Global/Core) Tools)


Tyler Andreasen
Wednesday

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

I have a simple (and maybe stupid) question: I have an IIS site running a ASP.NET Core 3.1 website. If I install the latest version of the SDK on the machine that deploys the DLLs, is it safe to say that the site will use the DLLs deployed from the publishing machine? Or, is it necessary to have the SDK also installed on the machine where the website is being hosted? I believe it to be the latter (without the SDK installed, the website will not function on the host machine) - and it's very difficult to tell what the exact version is that will be used by a website on a machine that has multiple versions of the SDK installed.


Jon
Wednesday

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

I've requested content-only project types several times over the years. On that horrible VS suggestion site it typically gets ignored and auto-closed, and as a project-system github issue it was closed with the usual "not planned" canned response.

There are many scenarios where that project type would be useful. Another common need I often have is to store and organize SQL scripts. Documentation comes to mind. And instead I end up using the incredibly clumsy pseudo-folders at the Solution level.


Rick Strahl
Wednesday

re: Using .NET Core Tools to Create Reusable and Shareable Tools & Apps

@Lex - yes I think you're right on that. .NET Core doesn't automatically roll forward to a higher runtime version, if you need to run both versions then you need to multi-target. Not sure if that's really necessary though - I would think you'd always want to target the latest version and keep moving the application forward as the SDKs rev up so a current install can run on the latest SDK.


Lex Li
Tuesday

re: Using .NET Core Tools to Create Reusable and Shareable Tools & Apps

Again, the best article I read on this topic. But maybe one thing is not expanded. The .NET Core tool example used here binds to .NET Core 3.1, so though it is not a platform dependent executable, .NET Core 3.1 runtime is required as prerequisite.

I owned such a tool that requires .NET Core 2.1 runtime. When a user only has .NET Core 3.1 SDK, and no 2.1 runtime, then after installing that .NET Core tool isn't able to run. So I assume the .NET Core tool project must use multi targeting, but I didn't have time to test that out.


Rob Bohn
Tuesday

re: Using WSL to Launch Several Bash Commands from an Application

An alternative to running bash.exe might be to use "--" such as this:

wsl -- ls -al | more;ping 127.0.0.1

Sanjay
Monday

re: Bypassing IIS Error Messages in ASP.NET

Hi Rick, First of all - it's really a great article. It has good amount of information to solve application level error. I wonder, if you have any suggestion for below scenario as well? I have asp.net (targeting to .NET4.8) application but all above tricks are not working if I pass url without .aspx extension. Suppose I request, "xyz.com/abc/default" (without .aspx extension); IIS returns 404 error while I was expecting my customer page.

So How do I map extension less url within our asp.net application to capture server level error and redirect to my customer pages.


jefferson vaughn
July 31, 2020

re: HttpWebRequest and Ignoring SSL Certificate Errors

I realize the post is old... but not finding any real good solutions yet...

my domain jeffersonvaughn.com is hosting a website in which I am running a .net core 3.1 application that executes a POST method HTTP request to server jvaughn1.powerbunker.com

I have generated a certificate on the jvaughn1.powerbunker.com server and have exported to a .pfx file in which I'm using in my .net application.

this http api request along with this .pfx file works when using Postman.

When my .net application makes the request I get...

An unhandled exception occurred while processing the request.
AuthenticationException: The remote certificate is invalid according to the validation procedure.
System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)

HttpRequestException: The SSL connection could not be established, see inner exception.
System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

my .net code looks like this...

startup...

            var cert = new X509Certificate2(@"C:\Users\jeffe\Desktop\Corei Solutions\products\core-i_rst\Apache HTTP_SSL\jvaughn1.powerbunker.com.pfx"
                                           , "corei");

            var handler = new HttpClientHandler()
            {
                SslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls
            };

            handler.ClientCertificates.Add(cert);
            services.AddHttpClient("coreiClient", c =>
            {
            }).ConfigurePrimaryHttpMessageHandler(() => handler);

            // handles issue with non-trusted certs...
            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

controller...

        var request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            //RequestUri = new Uri(Url + jsonRequest),
            RequestUri = new Uri(g_Url),
            Content = new StringContent(jsonRequest, System.Text.Encoding.Default, "text/plain"),
        };

        // for certificate authentication...
        var client = _clientFactory.CreateClient("coreiClient");

        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

Is there ANY possible way you can help shed some light on this and save me from this nightmare I been trying to wake up from!!!??? πŸ˜ƒ


Craig Boyd
July 28, 2020

re: JavaScript Debugging in a Web Browser Control with Visual Studio

This article just saved me. Good looking out Rick!


Jon K
July 27, 2020

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

Been digging through so many outdated articles and posts from various website the past couple hours to no avail, until I finally came across this one. Thank you so so much for an actual solution. My OCD thanks you.


Rick Strahl
July 27, 2020

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

@John - you're missing the point. I don't want to use Azure!. And even if I did it wouldn't change how the project is managed in Visual Studio.


Rick Strahl
July 27, 2020

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

@Alexandre - yes it's still there, but it's not on the start screen. If you're starting VS up use continue without code. At the main window use File β†’ Open β†’ Web Site. Or if you have a solution open Add β†’ Existing Web Site.


John Marsing
July 27, 2020

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

Have you looked at Azure Static web apps?


Alexandre Konioukhov
July 26, 2020

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

but I think we don't have Web Site Project in VS 2019 anymore. Or I miss something?


Zach
July 22, 2020

re: Entity Framework and slow bulk INSERTs

Helpful list of workarounds, thanks Rick.
The year is 2020. Seven years later, your take on EF still seems to be pretty accurate. It still doesn't rise above the the 80/20 rule.


Viktor MΓ‘rk TΓ³th
July 21, 2020

re: VSIX Installer Extension Manifest and Visual Studio Version Numbers

Hello Rick! Thank you for your article, it was very useful for me!

After the vsix update, I found an exception at Team Explorer/My work/In progress work and Available Work items, where I got this exception: System.Windows.Markup.XamlParseException: Provide value on 'System.Windows.StaticResourceExtension' threw an exception. ---> System.Exception: Cannot find resource named 'Microsoft.TeamFoundation.Controls.WPF.DraggableListBox'.

It occurs at VS 2017 and 2019, but works perfectly in 2015. Do you have any idea, what can be the issue here with the vsix xml?

Thanks, Viktor


Rick Strahl
July 19, 2020

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

@Nick - the project doesn't have a web.config by default, but the generated published output will always generate one. You can take that web.config file and add it to your project folder and it will be used, but the publish process will overwrite the <aspNetCore> key (in kind of unpredictable ways if you change values there). If possible **don't provide the <aspNetCore> key and let Publish create it.


Nick
July 19, 2020

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

Hello, great article. It looks like the default .net core 3.1 has InProcess mode enabled. Only if I explicitly change in the .csproj file to OutOfProcess it will switch to it. Also by default there is no web.config file. Can I add this manually? Also, i still see dotnet.exe process in InProcess mode.


Nick
July 19, 2020

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

Hello, great article. It looks like the default .net core 3.1 has InProcess mode enabled. Only if I explicitly change in the .csproj file to OutOfProcess it will switch to it. Also by default there is no web.config file. Can I add this manually?


James Curran
July 15, 2020

re: A .NET Color Console Helper

Hmmmm... I had this page opened in a tab since Monday before I got around to writing my regex example -- and Stuart sneaked in with his.


Rick Strahl
July 14, 2020

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

@Sunny - yes it's supported - you just have to make sure you set the appropriate build target when you build the application. Also - you can build the application under the Windows SubSystem for Linux which is native Linux so you can build and test the application locally.


Sunny Singh
July 14, 2020

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

I have a question on cross platform architecture of .net core.

So Can I compile the .net core application on Windows and deployed the binaries to Linux? Will it work?Is this the recommended way? I was reading the pluralsight blog https://www.pluralsight.com/tech-blog/dotnet-core-the-good-the-bad-and-the-ugly and here it is mentioned that it will work but it is not recommended.


Rick Strahl
July 13, 2020

re: A .NET Color Console Helper

Thanks @Stuart - that's great. I guess I need to get up on my Regex game - I didn't even remember you can do that. Works great!


Stuart Turner
July 13, 2020

re: A .NET Color Console Helper

If you use \[(?<color>.*?)\](?<text>[^[]*)\[/\k<color>\] as your regex, then you can use match.Groups["color"].Value for the color value and match.Groups["text"] for the inner text. No need to do the extract.


Rick Strahl
July 13, 2020

re: A .NET Color Console Helper

Thanks @Paulo. What kind of side effects are we talking about? Changing colors on multiple threads perhaps?

Makes sense not to set the value if it's not needed. Updated the sample for both WriteLine() and Write(). Good call!


Rick Strahl
July 13, 2020

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

@Brent - yeah the tooling that generates web.config seems to be broken unfortunately. With custom web.config if you add the .NET Core Module into the 'template'. The tooling will use the existing web.config but it will do some funky stuff if you have the Core module defined in the pre-existing file. If you leave out the Core Module then the rest of the settings should make it into the generated file and the Core Module will be generated in. In most cases that should be sufficient - unless you need some custom launch settings (like env vars etc. in which case some post processing is required).


Paulo Morgado
July 13, 2020

re: A .NET Color Console Helper

Console.ForegroundColor has side effects. It's cheaper to check for Nullable<T>.HasValue than setting Console.ForegroundColor when not needed.

I would go with something like:

public static void WriteLine(string text, ConsoleColor? color = null)
{
    if (!color.HasValue)
    {
        Console.WriteLine(text);
    }
    else
    {
        var oldColor = System.Console.ForegroundColor;
        var newColor = color.GetValueOrDefault();

        if (oldColor == newColor)
        {
            Console.WriteLine(text);
        }
        else
        {
            Console.ForegroundColor = newColor;

            Console.WriteLine(text);

            Console.ForegroundColor = oldColor;
        }
    }
}

Simon
July 13, 2020

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

Today I figured out that .NET Core SDK includes the runtimes, also for IIS but does not register them in IIS as Modules. For me the AspNetCoreModuleV2 was still missing after installing SDK 3.1.301. I furthermore could not find the aspnetcorev2.dll but only the aspnetcorev2_inprocess.dll in the directory of the sdk. The IIS Modules Folders C:\Program Files (x86)\IIS\Asp.Net Core Module\V2 and C:\Program Files\IIS\Asp.Net Core Module\V2 were not existent. Conclusion: I had to install the Hosting Bundle separetely besides the SDK to get my websites working. Hope this helps for clarification. Can you integrate this in your post Rick?


Brent
July 13, 2020

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

How do you add IIS modifications the auto-generated Web.config file in an C# ASP.Net core project?

I tried adding a Web.config to my project, but this caused problems by overriding the launchSettings.json.

Eg To add things like:

Removing IIS error handling:

<httpErrors existingResponse="PassThrough">
  <remove statusCode="502" subStatusCode="-1" />
  ...
</httpErrors>

And disabling modules:

<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <remove name="WebDAV" /><!-- Add this -->
      </handlers>
      <modules>
        <remove name="WebDAVModule" /><!-- Add this -->
      </modules>
    </system.webServer>
  </location>
</configuration>

old_guy
July 12, 2020

re: Linq to SQL DataContext Lifetime Management

so here it is during COVID-2020, and i find myself reading an article about Linq2Sql...and find myself on a project where they said..." turn our Access database into a SQL one and use Linq2Sql"... lol

So, i jumped into my Einstein time-machine back to 2003 to deal with Jet, while surfing my way upto 2010 and ACE drivers.. finally, landing firmly back into 2008 to deal with Linq2Sql and... ya, that DataContext is a bugger.

After having worked with EFCore since dotnet core RC 1.0, I find this experience brutally painful.

Getting a simple factory working with a repository interface has proven to be challenge worth failing against... but you can only do so much with this older technology where a concrete class like one made with SQLMetal is a herculean monolith of dumpster fires.


Ken F
July 01, 2020

re: IIS Channel Listener Errors in Windows 10 Insider Build 14342

Thanks for the post and all the comments. I recently upgraded to WS 2016 and encountered the Listener Channel failure error. While most applications can switch to 64-bit, one could not because it depends on some 32-bit code. In my case, the problem is indeed with the Microsoft URL Rewrite module. It had been working fine. But after the upgrade, I had to uninstall-reinstall it or install-repair it. So, one thing to check is your installed modules/DLLs if your 64-bit Application Pools work, but not your 32-bit.


Aidas Kasparas
June 30, 2020

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

Hi,

Thanks for the article. I was wondering what are reasons why you give control to ASP module starting at the root of website and then finding ways to get control back, instead of just registering application at /api URL and letting IIS serve root directory directly.


Rick Strahl
June 24, 2020

re: Using Angular's Live Reload Web Server to Refresh Pages on a Phone

@Jo - yes those tools are available but they don't usually render anything like what actually renders on the phone. I'm using my every day iPhone and a burner Android device for testing and they render vastly different than what you see in those Chrome resized previews. They work in a pinch if you want to get a general idea what things look like, but if you need need to tweak layout and see what things like line and box wrappings look like there's no substitute for running on an actual device.

Before - with the build and deploy then test cycle - I would be more inclined to do what you describe, but with the ability to run on device with live reload it's so easy that there's little reason to not do it.


JO
June 24, 2020

re: Using Angular's Live Reload Web Server to Refresh Pages on a Phone

I usually use Chrome's device simulation mode available in the DevTools where you can select various iPhone and Android device display dimensions. Probably not 100% accurate, but Safari also uses webkit for layout, so for styling it's probably pretty close. I don't know how many times I've suffered with some less than optimal solution like you described before I finally got irritated enough and investigated if there was a better way only to find there was and I should have been doing it for longer. It's a lot for sure.


Krisztina
June 24, 2020

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

Due to a programming error I accidentally created dozens of nested folders on my hard drive, 39GB data in a fraction of a second. I tried everything to delete the folders but due to the nested structure the path became so long that Explorer simply couldn't handle it. Your solution was the only thing that worked and I was able to delete all that redundant data, thank you so much!


Steven Rothwell
June 23, 2020

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

One thing you may want to note in the article is where the app.Use() needs to be in the Startup.cs. I had to add it above app.UseRouting(); but below app.UseStaticFiles(); for it to property rewrite the url.


Nithya
June 19, 2020

re: IPad Scroll Issues with Fixed Content

I used content="width=device-width, initial-scale=1.0,maximum-scale=1.0,shrink-to-fit=no,user-scalable=0" this in my meta tag at section and put style like this html,body{ overflow:hidden;} but it works for me...I don't know it will work for you

Thanks..```


Simon Price
June 17, 2020

re: Custom Message Formatting in WCF to add all Namespaces to the SOAP Envelope

I am having some trouble getting this to work in .Net 4.7.2 WCF Application. I have followed the steps you mention here exactly and cannot get the output to change.

I have created the 3 files as suggested and added the attribute to the method that will be calling it however I do not have a references.cs file either as the service was mainly created from the WSDL file as we are taking over \ re-rewriting a service from a client.

I need to change the prefixes from s:envelope to SOAP-ENV:Envelope and add some namespaces into this object too.

Can you offer some suggestion?


Claudio
June 15, 2020

re: Displaying Nested Child Objects in the Windows Forms Designer Property Grid

Hi, Rick, thanks for the great article. Your example works great with Win Forms and Net Framework 4.7.2 . Do you know how to get it to run on net.Core 3.1? There I see the category and the object in the property grid, but you can't expand it. I cant find a solution to get it work under net. Core. Maybe you have a tip for me. Regards Claudio


Santosh
June 13, 2020

re: ASP.NET Core and CORS Gotchas

Hi I am facing the same problem as Sushmita above when calling my Asp.net Core WebAPI from Angular app for put/post request with GEt requests working.

I need windows authentication with specific origins allowed and the only way to get it working is enabling Anonymous authentication in launchSettings.json as well !


Rick Strahl
June 12, 2020

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

@Hammurabidoug - AFAIK - no. ASP.NET Core doesn't expose a generic ServerVariables collection of all the variables that IIS exposes. But even when you could do that IIS wasn't exposing the name I think the closest is: APPLICATION_MD_PATH which gives something like /LM/W3SVC/1/ROOT where 1 is the site id. I don't know how you would be able to access that in Core however...


Hammurabidoug
June 12, 2020

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

Hi Rick. As always, this is excellent stuff.

Do you know if there is a way to get the name of the web application when running in IIS? Same, for example, you have two IIS web applications pointing to the same directory where the code is. Can the code identify the name of the web application?


Nick
June 11, 2020

re: Updating Assembly Redirects with NuGet

I've reference this page and used this command a lot. Thanks so much for posting this and keep it up!


mms
June 11, 2020

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

This is not good.

Recycling on every Virtual Directory change/create (for which I can't really think of a good reason) combined with the fact that IIS can't serve Symbolic Link directories (it does not recognize any file changes and serves stale content), makes it unusable for us for a very simple use case 😦 IIS needs to be rewritten, though I thought it was already.

Any way perhaps that url rewriting can be used to serve files out of a folder other than they physically exist? Need to be able to create these rewrite rules at runtime without bringing down the domain.

https://stackoverflow.com/questions/6698481/how-do-i-prevent-iis-7-5-from-caching-symlink-content


Rick Strahl
June 10, 2020

re: Using Let's Encrypt with IIS on Windows

So what is your use case here? You can't really have multiple machines with the same domain name? The only scenario I can see there is a load balanced cluster, but then you probably will have some sort of front end proxy that handles the incoming secure connection and forwards to the backends over plain http (or self-signed certs)...


Stanley Barnett
June 09, 2020

re: Using Let's Encrypt with IIS on Windows

Hi Rick,

  1. So I would deal with the specific sub/domains for each and every machine independently, without regard to any other machine? And if I need to use a specific cert for a specific machine elsewhere, I would need to export it from the registered machine with the key for use on other machines. In other words, the machine registering it can be made to automatically update itself while all other machines that needs that cert would have to be manually exported and imported into the other non-registered machines?

  2. So wouldn't I have to manually update all the other machines that requires the cert to that site such as FireFox (which immediately comes to mind) on the other machines? If so, then having to do this on many machines every 2-3 months could raise the hassle factor too high, correct?

Thanks, Stanley


Rick Strahl
June 09, 2020

re: Using Let's Encrypt with IIS on Windows

@Stanley - not sure what you're asking exactly. Domain validation by lets encrypt occurs by individual subdomain not to the top level domain. Meaning you can register d1.domain.com and d2.domain.com on different machines. If you use WinAcme you'll want to be doing that anyway because WinAcme handles the renewal and adding to IIS. So you basically set up WinAcme on each server that needs it then run the domain registration and the auto-renewals will handle via scheduled task that fires once a day and checks for updates.


Stanley Barnett
June 08, 2020

re: Using Let's Encrypt with IIS on Windows

Hi Rick,

I've been a fan of West-Wind and you going all the way back to the dev conferences that Will hosted in Milwaukee and SouthWest Fox in Gilbert. I've attended all of you workshops in every conference that I attended (5-6), that you have spoken at and I have learned so much. And thanks for continuing to share.

If I'm hosting www.domain.com and mail.domain.com on 2 different servers (both Windows 2016 Web Server and Windows 2016 Exchange Server), would the hassle outweigh the benefits since renewalls cannot be automated and expires too quickly?

I understand I can automate one of them (say the, www server), but the other server (exchange) would have to be manually renewed by creating a MyKey.pfx file containing both public and private keys using Window's export and import routines from cert manager on the www server and importing it into the exchange server.

Some info about our setup for use with LetsEncrypt... We use host headers with a single ip address and SAN certs currently, and I always cringe to think about a cert name change to the san cert and renew all related sites. All sites hosted on the IIS server has their mail counterpart hosted on a separate mail server. Some sites are hosting ftp and they are on their own ftp server.

Am I understanding this correctly? If not, please explain how I can automate and use this as the savings in time and cash are great.

Another related question... You or someone mentioned that it is standard practice to add www.domain.com, mail.domain.com, ftp.domain.com, sales.domain.com to the LetEncrypt cert. Normally when getting a san with a long list of domains that will be added to the cert, would the www. subdomain need to be added as many authorities would use it (www.) as the CN (common name) and would not be included in the domain list. So, does LetsEncrypt use the CN schema?

Thanks, Stanley


Brandon Moore
June 07, 2020

re: Accepting Raw Request Body Content in ASP.NET Core API Controllers

With this, it seems you must include [FromBody] and you cannot include more than one parameter with this attribute. Is there any way around this limitation to allow for multiple primitive parameters? I used the previous incarnation of this solution you shared for web api to handle multiple primitive parameters and it worked fabulously... can't seem to find a way to do the same here though 😦