Recent Comments



Rick Strahl
Friday

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

@Kyriakos - So far I haven't seen or heard of any issues. The beauty of all of this is that it is easily interchangable. If you are relying on a specific process model, then I would argue there's a much bigger problem in the application that is too tightly coupled to its environment. Unless there's a very good reason to do this, I think that's the first thing that should probably be addressed.

Other than that it seems like a Win-Win, but time will tell. This is a new feature and only time will tell what breaks.

It's also important to point out that .NET Core 2.2 is not an LTS Release meaning it's not considered a full release. According to MS we'll have to wait quite a while for full LTS status with .NET Core 3.1 which looks to be out quite a bit (late this year, more likely early next).


Rick Strahl
Friday

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

@Rick - make sure that you build a Production build when you publish. If you're using the command line:

dotnet publish -c Release

which should by default set everything up for production.

You can specify environment variables as part of the web.config (from the docs):

<aspNetCore processPath="dotnet"
      arguments=".\MyApp.dll"
      stdoutLogEnabled="false"
      stdoutLogFile="\\?\%home%\LogFiles\stdout"
      hostingModel="InProcess">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
    <environmentVariable name="CONFIG_DIR" value="f:\application_config" />
  </environmentVariables>
</aspNetCore>

You know I've railed against this everything default is Development in .NET Core for a while publically and I absolutely hate that! For the reasons you outline every application I build (HTML or API) has a request in it that shows me some stats about the application and one of those settings is the environment that shows me environment and release/debug state.


Hugo
Friday

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

I believe that may not be so easy, but, do not support sharing memory between applications it's what stopping me to move to .NET Core and I consider .NET Core an incomplete framework.

The old ASP.NET provides at least to ways to share memory resources:

  1. Share the application pool
  2. Thru aspnet_intern: https://visualstudiomagazine.com/articles/2017/11/29/improve-startup-time.aspx

I awaited for .NET Core 2.2 because of In-Process (that was supposed to be released on 2.1) and faced this issue.

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

Thanks a billion for such an insightful post. This blog is a true goldmine. I experimented with setting IIS to point at the source-code directory of my .Web project (which contains Web.config and /bin with all dlls). The solution runs in in-process mode (following all of your instructions):

  • So far so good, everything seems to work fine (debugging, breakpoints and everything else)
  • To sweeten the deal I also tweaked the pre/post build events of the .csproj to have it spawn and remove an 'App_Offline.htm' right next to the Web.config and inside the /bin folder so as to enable VS to overwrite dlls upon recompilation (no more "dll has been locked by process XYZ").

Just a quick question: Is there something obviously wrong with this approach that is bound to byte us back if we employ it to develop our solution like this?

Thank you in advance, keep up the good work and may Winds be under your Radiant Wings, always.


1LadyInDC
Thursday

re: JavaScript JSON Date Parsing and real Dates

Thanks so much Rick! Parsing dates with JSON had me STUCK for like two whole days and then I came across this!


Germán
March 19, 2019

re: Rendering ASP.NET MVC Razor Views outside of MVC revisited

Hello Rick,

Do you think that what you've posted is a solution for this? https://stackoverflow.com/questions/11996205/asp-net-mvc-exception-rendering-view-in-new-thread

Quoting: "The error I'm getting is: 'Value does not fall within the expected range', when the viewResult.View.Render method is called.

I'm guessing this has to do with the fact that the controller context is no longer valid in the new thread, but I'm not sure."


Mladen Mihajlovic
March 19, 2019

re: Hosting SignalR under SSL/https

This is one of those things that I don't need very often but when I do I've forgotten everything and need to look it all up again 😃

Just a note that netsh has been "superseded" by powershell these days so the above commands can actually be done using the following:

netsh http add sslcert ipport=0.0.0.0:8082
           appid={12345678-db90-4b66-8b01-88f7af2e36bf} 
           certhash=d37b844594e5c23702ef4e6bd17719a079b9bdf

translates to

Add-NetIPHttpsCertBinding -IpPort "0.0.0.0:8282"  -ApplicationId "{12345678-db90-4b66-8b01-88f7af2e36bf}" -CertificateHash "d37b844594e5c23702ef4e6bd17719a079b9bdf" -CertificateStoreName "My" -NullEncryption $false

you might also need

New-SelfSignedCertificate -Subject "CertSubject"

Rick
March 18, 2019

re: ASP.NET Core InProcess Hosting on IIS with ASP.NET Core 2.2

The one problem I've seen with this is in development the environment is detected as "Development;Production", which matches nothing. ASPNETCORE_ENVIRONMENT was set to "Development" in all the places the documentation says it's possible to set it, but I couldn't find where that "Production" value was coming from. Switching back to out of process made it work as described, reporting just the value of ASPNETCORE_ENVIRONMENT.


Milan
March 18, 2019

re: ASP.NET Core InProcess Hosting on IIS with ASP.NET Core 2.2

Very well explained. You covered pretty much all questions that I would normally have for such a feature. Seeing the call stacks, your tests results, and everything else makes this very valuable article. I will definitely feature this post in my next newsletter.

Thank you.


Cole
March 15, 2019

re: Easy Configuration Binding in ASP.NET Core - revisited

Hi Rick,

This works great, except for when you have an array of objects. Let's say you have an array of email called Emails. If you do it as a list of email, it comes up null. If you create a poco for Emails, it will have no values. I can't figure out how to get this to bind.


Sebastian Redl
March 12, 2019

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

Excellent information. But your handling of content type and the body data is fragile. You should use the MediaType struct from Mvc as a helper. Then you can do things like this:

private static readonly MediaType TextPlain = new MediaType("text/plain");

var mediaType = new MediaType(httpContext.Request.ContentType);
if (mediaType.IsSubsetOf(TextPlain)) // deals with capitalization and header parameters
{
  // deals with encoding parameter in content type and falls back to UTF-8 if missing or invalid
  var reader = new StreamReader(httpContext.Request.Body, mediaType.Encoding ?? Encoding.UTF8);
  var content = await reader.ReadToEndAsync();
}

Rick Strahl
March 11, 2019

re: More on ASP.NET Core Running under IIS

There is another post coming soon.


X LU
March 11, 2019

re: More on ASP.NET Core Running under IIS

Nice Post!

Could you also add IIS In-process hosting model with IIS HTTP Server instead of Kestrel server since MS states it has higher performance since it is in-process?


Matt Keys
March 08, 2019

re: Flexbox Containers, PRE tags and managing Overflow

Just writing to say thanks. Ran into this issue today and it would have taken me a long time to sort this one out without this post.


Lloyd
March 07, 2019

re: Bootstrap Modal Dialog showing under Modal Background

Thanks for this. I was wondering how the hell I was going to diagnose this problem when z-index had no effect.

Quick Google produced this.


Kevin W Werges
March 06, 2019

re: Building a better .NET Application Configuration Class - revisited

Hi Rick! I know this article is aging, but I wanted to say thanks for the work on posting it. I did have a question involving updating the configuration classes. If I were to define a configuration file as having properties for First Name, Last Name, and some Id, but then later added a property for a phone number, would the westwind library automatically update the existing configuration to include that new property if the configuration already exists? Also, what happens if the property were to be removed in the class, but it still is present in the configuration file?

I know this is a pretty basic question, but I'm interested in understanding the implications of updating these classes and legacy support for older versions of an application.


Rick Strahl
March 04, 2019

re: .NET Standard 2.0 - Making Sense of .NET Again

@Husky - Well, maybe you're not quite up to date on how .NET has evolved. It runs on linux (no Windows license required) and you certainly don't have and never did have to use SQL Server. You can use PostGres, MySql, SqLite, MongoDb - whatever you like. The eco system is very rich. Further, while I think the versioning path has been somewhat torturous, I think Microsoft has been on a steady and well defined path that hasn't drastically changed anything in the last 5 years since the .NET Core journey started, but rather working through incremental improvements of the platform.

You can hate on Microsoft all you want and use something else, but if you do at least have your facts straightened out and not based on some perception from 10+ years ago. Other stacks change too - that's technology changing and improving. Since you bring up Python - there have been several major breaking changes in version updates that had people up in arms for years. This shit unfortunately happens with tools that have been around long enough to live through technology generations. And Microsoft more than anybody at least tries to let the old technology continue to run for long, long times past their support dates on current hardware.


Husky
March 03, 2019

re: .NET Standard 2.0 - Making Sense of .NET Again

I agree with @Edward, @Alex, @Jose. Every 6 to 12 month MS pushes the next "big thing" down everybodies throat and says "this is it" and after a while, only to find out that its crap and was not adopted (Silverlight,WPF,...) It leaves the impression the technology stack is being changed too fast too often chasing some holy unified platform that is supposed to do everything. After 20+ years as a .NET/MS-SQL developer I switched to Python, Django on a major project and I am glad I did. Guess what, Microsoft, Linux, Mac OS all platforms work fine with Python and without the confusing mess behind the scenes that MS created. For customers the Microsoft server (Web or SQL) licence costs are horrendous. Any Linux server blows the MS solutions away if performance, RAM usage and price.

What I liked about @RickStrahls post the most is the Topic "..making sense of .Net again!"...well said! Exactly! hit the nail on the head, cause .NET lost it's sense.


Rick Strahl
March 02, 2019

re: Automating IIS Feature Installation with Powershell

@Josh - you are right in that I make some basic assumptions here. This is a developer Weblog and I post developer stuff and if you're not a developer dealing with this stuff this blog will be a slog.

That said - if you can't figure out how to search for Web Platform Installer or Chocolatey then you probably are not in the intended audience. No offense, but true. That doesn't mean you can't use any of this, you just need to do a little extra work to add to your repertoire of tools. If you are administering a Web Server those two distribution tools will be critical and it'll be a worthwhile. Happy searching...


JoeM
March 01, 2019

re: Automating IIS Feature Installation with Powershell

A couple of failings here: You never once mention how/where to get "WebPlatform Installer;" nor "chocolatey" I love chocolate; but you seem to have built-in assumptions that all readers magically know what there are and where to find them. One commenter at least provided a link to WebDeploy.

Those are essential refernces, if you expect readers easily be able to easily follow this. That said, this is AMAZING work - nothing short of 'really cool!'. I've used this quite a bit since you first posted it. THANK YOU!

So, what is this magical "WebPlatform Installer" - is it an MS piece? Another feature? Where can I get it? And, same question for "chocolatey" - I will Google for these vs. waiting for a response, but ???


Matt Frear
February 28, 2019

re: Using .NET Standard with Full Framework .NET

Great post Rick, thanks for clearing up a lot of confusion!


Jo
February 28, 2019

re: GZip/Deflate Compression in ASP.NET MVC

Hi Rick, Thank you for this code, I use it to compress some of my web API methods.
But what if someone posts compressed data to my web API? I can't find a way do decompress POST's to my web api. How can I achieve this? My method is like public ResponseDto Sync(InputDto input) If I post compressed data to this method, the input-parameter is null. If I post uncompressed data, the parameter is filled in. Thanks for your reply and your time.


Sreejith
February 27, 2019

re: Hosting SignalR under SSL/https

Hi i read through your post i am also facing a similar issue not sure what is the correct way to resolve, it works in http://localhost:port/signalr but when i host it in IIS with https://domain.com/api/signalr it says and http error 404 with the following error message No HTTP resource was found that matches the request URI http://domain.com/api/signalr/negotiate?clientProtocol=2.0&connectionData=[{"name":"progress"}]&_=1551264914856' SignalR error: Error: Error during negotiation request. This is my client js call $(function () {

    //$.support.cors = true;
    $.connection.hub.logging = true;
    $.connection.hub.url = Config.APIHost + "api/signalr";
    var chat = $.connection.progress;

    chat.client.addProgress = function (message, percentage) {
        
        ProgressBarModal("show", message + " " + percentage);
        $('#ProgressMessage').width(percentage);
        if (percentage == "100%") {
            
            ProgressBarModal();
         }
    };

    $.connection.hub.start().done(function () {
        //debugger;
        var connectionId = $.connection.hub.id;
        console.log(connectionId);
    });


    $.connection.hub.error(function (error) {
        //debugger;
        console.log('SignalR error: ' + error)
    });
});

The request header although has the https://domain.com/api/signalr/negotiate?clientProtocol=2.0&connectionData=[{"name":"progress"}]&_=1551264914856'

I am really not clear on what is wrong here.


Rick Strahl
February 26, 2019

re: Using .NET Standard with Full Framework .NET

@Diogo - go for it as long as you point back to the original article and credit it.


Diogo Damiani Ferreira
February 26, 2019

re: Using .NET Standard with Full Framework .NET

Hi, Rick! Very nice post. It will help a lot at the understanding of the topic.

Would you mind if I translate it to pt-BR? It would help to spread that information.


Rick Strahl
February 21, 2019

re: Using .NET Standard with Full Framework .NET

@Matt - thanks fixed. .NET Standard 2.0 is implied in the entire discussion since 2.0 is the focus of this post, but point taken. It makes it clearer. Went through and explicitly added the 2.0 label to a couple of other places.


Matt Slay
February 21, 2019

re: Using .NET Standard with Full Framework .NET

*>> .NET 4.7.2 is the first version of the full .NET Framework that is fully .NET Standard compliant without any additional dependencies. *

It seems incomplete to state that something is ".Net Standard compliant" without referencing what **Version **of .Net Standard you are referring to.

For instance, according to the chart, .Net Framework 4.6.1 is fully compliant with .Net Standard 1.4

So, it seems your statement should have read:

".NET 4.7.2 is the first version of the full .NET Framework that is fully .NET Standard 2.0 compliant without any additional dependencies."


Rick Strahl
February 20, 2019

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

@ST - not sure what you're asking. If you have form data it should map to object properties when using [FromBody] with application/x-www-form-urlencoded. If content is application\json it should deserialize into the object.


ST
February 20, 2019

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

Nice post. For application/x-www-form-urlencoded, is there a build in IInputFormatter?

I'm using a [FormBody] and the HTTP Post can be a full HTML form submit or an AJAX JSON post.


Kevin LaBranche
February 20, 2019

re: Using .NET Standard with Full Framework .NET

Fascinating. I understood .Net Standard in principle but I didn't realize it was doing as you demonstrated for anything older than 4.7.2.


NGR
February 19, 2019

re: Bootstrap Modal Dialog showing under Modal Background

What I ended up doing:

$("#mymodaldiv").modal();
if(!$("#mymodaldiv").parent().is('body'))
    $("#mymodaldiv").appendTo("body");

Dave Hoogendoorn
February 18, 2019

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

Hi Rick, great work! Could you explain on how to read context.Request multiple times using GetRawBodyStringAsync. I tried to extend it with Request.EnableRewind, but I cannot get a hold of it. Thanks, Dave


Rick Strahl
February 17, 2019

re: Automating IIS Feature Installation with Powershell

@anupam - Nope - not really. You know you'll need ASP.NET which means you'll need most things I mentioned above but it's still on a case by case basis to pick out what you need.


Scott Ferguson
February 17, 2019

re: Easy Configuration Binding in ASP.NET Core - revisited

Thanks Rick. Without knowing what the 'prescribed' ASP.Net Core way was, the way I imagined configuration would work for DI is pretty much exactly how you showed it in this article. I appreciate the effort you've gone to documenting it! (a year or more ago)

Cheers


Anupam
February 16, 2019

re: Automating IIS Feature Installation with Powershell

Super article Rick, Thanks ! is there a way to figure out what minimal set of components are required, by looking at the web.config of a webapp?


Rick Strahl
February 15, 2019

re: WPF Hanging in Infinite Rendering Loop

@mv10 - Yup. WPF could be so much better though with a few relatively small enhancements. Easier binding expressions that support expressions would reduce a shitload of code for one. Some mechanism for inheritance or multi-extensions in styling would make life so much easier. And then the big issues - moving forward with a newer version of DirectX.

It sucks that Windows Desktop development is in such disarray. Nobody has a clear picture of direction. Microsoft has wishful thinking with UWP, developers have wishful thinking with either WPF or WinForms. Electron? Microsoft now owns that too.

None of these platforms provide the functionality that most people want in a desktop platform. UWP - too fucking limited to build useful desktop apps. If I want a mobile/table style app I can get a limited sandbox environment from a Web browser and be more flexible with that. I want a platform that can do desktop things - that's why I'm building a desktop app in the first place. WPF is a bear, but I agree once you get over the hump it's great, but there are still so many things that are difficult that shouldn't be. The hard stuff is easy, the easy stuff often is hard. WinForms - still the easiest solution and most productive solution IMHO but the UI is lacking these days. The enhancements for high dpi support in 3.0 might change that though (the 4.7 enhancements to that effect didn't work worth a shit though so not sure if that will pan out).

All of that that just leaves - confusion. No good go to solutions really, all solutions with major drawbacks. Microsoft is simply ceeding the Windows desktop just like they did with Mobile which just seems insane given the pre-dominance of Windows to date still. For all the neglect Microsoft is piling on the desktop platforms they deserve to lose Windows pre-dominant status for the sheer complacency of it.


MV10
February 15, 2019

re: WPF Hanging in Infinite Rendering Loop

Ugh, I was just considering bumping some of my WPF apps to 4.7 today... guess I'll wait. Better safe than sorry. While WPF on .NET Core and the move to open-sourcing it is encouraging, I sure wish MS would throw some real resources at it for a short while. I read somewhere the original WPF had almost 1000 devs working on it full-time. The Windows desktop is still their bread and butter (though I suspect Azure is encroaching), and WPF is their best option by a long shot. UWP is a mess and not at all appropriate for 90% of their market (aka the desktop), whereas WPF is frankly pretty amazing once you get past the initial learning curve (on my mind a lot lately, I'm probably facing bringing a bunch of web-app-handicapped devs into the WPF world in the near future... dat curve...).


Alberto Silva
February 15, 2019

re: Creating a dynamic, extensible C# Expando Object

Great article, many thanks! I used your approach when submitting to Sap Business One on Hana via OData a known entity with custom user fields which are exposed as properties. With this approach, I just added the inheritance to your Expando object on the entity class I needed to submit and using the named indexed dictionary, set the value of the custom user fields, and the server processed it perfectly!


Rick Strahl
February 14, 2019

re: External Network Access to Kestrel and IIS Express in ASP.NET Core

@adrian - launchsettings just affects visual studio (and other tooling) launching, not runtime launching.


Jol Makahari
February 14, 2019

re: External Network Access to Kestrel and IIS Express in ASP.NET Core

1.) Open port for incoming requests in FW 2.) setup Port forwarding in router 3.) Added: .UseUrls("http://0.0.0.0:15536") // added for external access .UseIISIntegration() // added for external access

4.) and executed: netsh http add urlacl url=http://*:15536/ user=Interactive listen=yes

It's working now, thanks!


Rick Strahl
February 14, 2019

re: Strongly Typed Configuration Settings in ASP.NET Core

@Simon - Section doesn't refer to the Json section, but to the structure of the configuration layout. That layout can be created with any of the added providers (ie. Json, CommandLine, Environment etc.). They all use the same layout format, so you can still use sections with Environment variable or command line arguments by naming them with "database:connectionString" for example, which lets you references the database section.


Simon
February 14, 2019

re: Strongly Typed Configuration Settings in ASP.NET Core

Great Post! I especially like the way you can .Configure(..GetSection(..)) to automatically create strongly typed settings object without any mapping code, but I have one question...

What if there is no section? no json settings? what if the data you want has been added to IConfiguration using AddCommandLine() or AddEnvironmentVariables()?


Rick Strahl
February 12, 2019

re: GZip/Deflate Compression in ASP.NET MVC

@Hamed - depends on what you want to do. If you want to compress all your content the Web.config setting is the right choice. I don't think it's a good idea to compress everything - I think it makes sense only for large documents that are serving tons of data down to the client. If you have pages that are relatively small (under 10k) it's probably not worth compressing.

I tend to use compression on specific pages that are either large or high volume.


Hamed Hossani
February 12, 2019

Frank
February 12, 2019

re: Opening a Web Browser with an HTTP Url from Visual Studio Code

Finally, I've been looking for this functionality but have not been able to find it elsewhere. Works great! Now, I wish there were a way to tie the task to your currently open project so it would use the appropriate URL no matter which project I'm working on.


Rick Strahl
February 11, 2019

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

@Sven - working on another post that's mostly done for the new InProcess hosting model. Hopefully will be out in the next week or so.


Rejwanul Reja
February 11, 2019

re: Easy Configuration Binding in ASP.NET Core - revisited

It's really a helpfull article to configure and extract value from appSettings.json on asp.net core. The section "Raw Configuration Value Binding" was needed for me. Thanks lot Rick Strahl.


Chris
February 10, 2019

re: Finding the ProgramFiles64 Folder in a 32 Bit App

On 64 bit machines, the Program Files location where applications install changes the behaviors of Windows > launchers. For example if you compile a .NET Desktop application with Any CPU and you launch from Program Files (x86) you'll launch as a 32 bit app. Launch from Program Files and you'll launch as a 64 bit application. Windows provides a launching process some hints that suggest whether the app should run 32 or 64 bit modes.

Whoa! Never heard about that. If I actually try this:

using System;
public class Program {
   public static void Main(string[] args) {
     Console.WriteLine(IntPtr.Size * 8 + " bit");
   }
}

Compile it simply by invoking csc.exe foo.cs. And then run corflags.exe foo.exe, you'll get this:

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 0x1
ILONLY    : 1
32BITREQ  : 0
32BITPREF : 0
Signed    : 0

So something that resembles, "Any CPU" (and 32bit preferred disabled).

Then copy the foo.exe file to both C:\Program Files (x86)\foo.exe and C:\Program Files\foo.exe. Both will output "64 bit" on the console.

Can you elaborate where you found that information or if you could reproduce it somehow.

Note: tested this on Windows 7 and with .NET full framework 4.7.


Sven Vranckx
February 10, 2019

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

Excellent tutorial, but you may want to update the AspNetCoreModule link to point to the latest release: https://docs.microsoft.com/nl-nl/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.2#install-the-net-core-hosting-bundle (the link in the article still points to a release candidate)

Thanks!