Recent Comments



Rick Strahl
Yesterday

re: Using Let's Encrypt with IIS on Windows

Walt - I use https redirects and it seems to work. I think for the first registration it has to be http, but for renewal https requests seem to work for me.


Walt
Yesterday

re: Using Let's Encrypt with IIS on Windows

Hi.

Thanks much for the post on Let's Encrypt. I am now using LE for a company home page. However, I want to redirect all HTTP traffic to the HTTPS protected web site, and from what I understand, LE uses HTTP to request renewals? Will such a redirection cause issues with the automatic renewal?

Thanks much for any suggestions / help! Walt


Gunther
Tuesday

re: New CODE Magazine Article: Getting down to Business with ASP.NET Core

A timely article for me, working on my first Asp.NET Core app.
I'd be interested in a "How To..." article on deploying an Asp.NET Core app to an IIS server -- if you're looking for future topic ideas. :)


Damon Allison
Tuesday

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

Great article. It gave me a "real world" state of the .NET Core platform. From my limited usage of .NET Core, I completely agree with Rick. The current state of tooling, standards, direction is confusing at best. Microsoft desperately needs to simplify their messaging to developers.


Rick Strahl
Saturday

re: Faking out the .NET Runtime Version

Thanks Knaģis. I have to experiment to see how this works, but adding a 4.6.2 launcher project and leaving the main project as a 4.5.2 project seems like a great way to go. Just have to get the naming right... thanks for the inspiration.


Kenan
Saturday

Knaģis
Saturday

re: Faking out the .NET Runtime Version

A second project targeting 4.5.2 would enable compile time checks verifying that all framework methods are supported both in 4.6.2 and 4.5.2.

I think that the IDE actually understands when a file belongs to multiple projects because I have seen it hinting in the Intellisense when a certain framework method is only available in one of the projects.

In CommonMark.NET I did manage to set up the projects so that I have only one that shows the files in Visual Studio (so that is the one where I would add/remove files etc.) but there are others that import this project but then compile it against a different target framework.


Mark
January 13, 2017

re: New CODE Magazine Article: Getting down to Business with ASP.NET Core

My CODE subscription lapsed years ago. I just renewed it :)


Rick Strahl
January 12, 2017

re: Faking out the .NET Runtime Version

@Knaģis - Yeah in hindsight that would be cleaner - also for addin creation so you didn't have to reference the EXE. I may still do that at some point.

What do you mean by check the API usage?


Kevin
January 12, 2017

Knaģis
January 12, 2017

re: Faking out the .NET Runtime Version

I would add a second VS project that has most of the content shared with the existing (by importing the main project) but set it to use .NET 4.5.2 for compilation. This way building the solution would automatically check the API usage.


Johan
January 12, 2017

re: JavaScript JSON Date Parsing and real Dates

I want to add that in ISO 8601 so called "time zone designator" is just an offset from UTC and not an actual time zone. For example, given time zone and valid local time instant in that time zone you can calculate offset from UTC but you cannot infer time zone from ISO 8601 date with some offset. Different time zones may have same UTC offset for many reasons (daylight saving time). Same time zone at different time instants may have different offset from UTC.


Edgars
January 12, 2017

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

Thanks for this article - very helpful. I have succesfully deployed my first ASP.NET Core API with IIS.

Maybe someone here can answer to my question. In previous ASP.NET Web API v2 it was possible to return Status Code pages from IIS. Actually this functionality worked by default without additional configuration. Is it possible to achieve same functionality with ASP.NET Core deployed on IIS? Respectively - return status code pages from IIS.


Rick Strahl
January 11, 2017

re: Faking out the .NET Runtime Version

@Benny - I wish that were so. But it doesn't work. I tried :-) The manifest hack does indeed change the multi-monitor setting, but it doesn't actual make the application behave properly when translating positions on another monitor when not dealing with the active window. IOW, without 4.6.2 it looks that WPF can't deal with two windows on two monitors simultaneously. It can in 4.6.2.

To test I tried the instructions from the document you pointed as that looked promising. It worked with 4.6.2, but when I rolled back to 4.5.2 I still see the exact same failing behavior I see with my approach of manually setting the DPI mode. There's something else they are doing inside of the WPF runtimes with 4.6.2 that is not covered by merely changing the DPI mode (and the change event handlers). It has to do with how WPF is translating the pixels on the secondary monitor when setting window positions. As it is I have to do apply a pixel ratio (ie. Scaled DPI/96) to width/height/top/left to get things to line up on either monitor. You can see this [here](https://github.com/RickStrahl/MarkdownMonster/blob/master/AddIns/ScreenCaptureAddin/ScreenCapture/ScreenCaptureForm.xaml.cs#L428) in the screen capture code.

It might be that my scenario is a very special edge case (I'm overlaying specifically placed WPF windows on a Windows pixel region) and it's possible the manifest/DPI Mode settings alone would fix some other issues like the auto-resizing of windows when dragged across monitors. However all that seems to work just fine even with System aware settings for me.


Steve
January 11, 2017

re: Windows Update Hell

It's amazing to me that people accept the idea that their Windows machine is theirs to control anymore. It's not. W10 is just more of big brother imposing their will.

Anyone who adopts W10 should realize their machine is simply an extension of Microsoft's global outreach program and that, in the end, have no real say about their lives.


Benny Bürger
January 11, 2017

re: Faking out the .NET Runtime Version

@Rick Yes you get the same result (by the way nice trick with the static constructor) but you don't have to use the hackish approach to compile against 4.6.2 and target 4.5.2 If you compile against 4.5.2 and use the manifest file and you use 4.6.2 the permonitordpiawareness will work. Using 4.5.2 your app will work too, but without permonitordpiawareness. You will not get an manifest error.


pran
January 11, 2017

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

superb explanation of the inner workings of Core with IIS. Do you plan to update this article for the latest version of Asp.Net Core?


Rick Strahl
January 11, 2017

re: Faking out the .NET Runtime Version

@Benny - you can do that with an API call (SetProcessDpiAwareness) as well so the manifest is really optional.

Calling this code at startup in static App(): https://github.com/RickStrahl/MarkdownMonster/blob/master/MarkdownMonster/_Classes/Utilities/WindowUtilities.cs#L184

gets the same results.

The problem is that that's not enough to get WPF to play nice when creating content on multiple screens - ie. main window on one screen secondary window on another. The per monitor DPI setting works for the main window and auto-window resizing, but not if you need to put content at precise locations on secondary screens - at least not without a lot of extra tweaking. I don't know exactly what's different in 4.6.2 but there's some other magic happening in the runtime beyond just tweaking the initial DPI settings switch and it only works in 4.6.2.

Doing it in code means I get to fallback to the default behavior without a manifest error that potentially leaves the app in an unstable state.


Benny Bürger
January 10, 2017

re: Faking out the .NET Runtime Version

Actual the best method is to target 4.5.2 and modify the App.config or manifest file as described in the following link: https://github.com/Microsoft/WPF-Samples/blob/master/PerMonitorDPI/Developer%20Guide%20-%20Per%20Monitor%20DPI%20-%20WPF%20Preview.docx?raw=true


Rick Strahl
January 06, 2017

re: Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control

@Mark - did you read the post? There's a whole section on that topic.


Mark Woan
January 06, 2017

re: Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control

Have you considered an alternative web browser control such as awesomium?


Rick Strahl
January 05, 2017

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

@John - no they use different hosting environments. Code should work the same. dotnet run uses Kestrel by default, but you can change what it runs using either the configuration settings mentioned in this post: https://weblog.west-wind.com/posts/2016/Sep/28/External-Network-Access-to-Kestrel-and-IIS-Express-in-ASPNET-Core


Jose
January 05, 2017

re: First Steps: Exploring .NET Core and ASP.NET Core

Fantastic, Rick!
As always, your post allows a developer to leap across the chasm of a new technology and hit the ground running. Thanks!


John Mark Isaac Madison
January 04, 2017

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

IIS and "dotnet run" are using two different execution environments I think. Juding by how running with IIS works, but "dotnet run" gets compilation errors.

Any tips on how to remedy?


JOn
January 04, 2017

re: Back to Basics: String Interpolation in C#

This is one of my favorite features in C# 6 as well. I've been using it heavily. I have an app that generates Entity Framework classes, a web app, and other source files, from reverse engineering a database. I've been using T4 templates to do a lot of it. But, I'm starting to wonder if it wouldn't be easier to just ditch T4 altogether and use multi-line strings and string interpolation for everything in a standard C# file. I did this for some of what I'm working on. The source files that I'm generating have so much conditional code in them that there is more conditional logic than static text. Plus, I'm annoyed by the fact that Microsoft doesn't even have syntax coloring for T4 template files. I've been using the extensions to Visual Studio for support for that, but, they don't recognize interpolated strings and in general are kind of flaky. I also use LINQ a lot. string.Join() is another one of my favorites, although I think that was always in .NET, though I didn't find out about it until later.

    private DbCommand <#= string.Join(", ", Context.Entities.Where(e => !e.IsView && e.Properties.Any(p => !p.NotMapped && !p.IsKey && !p.IsDatabaseGenerated && !p.IsNavigationProperty)).Select(e => $"update{e.Name}DbCommand")) #>;

bystander
January 04, 2017

re: Back to Basics: String Interpolation in C#

Things I wish you'd have said:

  • Interpolation uses the current culture. This is important to know if you're creating a string for machines rather than humans (e.g. building up markup or something).
  • Talk about the built-in Invariant() helper method.
  • Talk about getting a FormattableString from the interpolation rather than a string.
  • Mention that everything is boxed, an array is allocated and everything (including plain strings) go through a formatting step. For trivial usages like $"Hello {name}"this makes interpolation a lot more expensive than "Hello " + name with little benefits.

David Scheppers
January 04, 2017

re: Back to Basics: String Interpolation in C#

There's so much syntactic sugar in c# 6, I may have contracted syntactic diabetes :)


Rick Strahl
January 03, 2017

re: Using JSON.NET for dynamic JSON parsing

@JohnDoe - not inline of an object. That's not valid JSON. Top level arrays (ie. the document root) stars without a label.


johndoe
January 03, 2017

re: Using JSON.NET for dynamic JSON parsing

When serializing using dynamic json, is there a way to create a bracket(array) without a name in front of it? [ { level1:[{ [ {test:"test1"}, {test:"test2"} ] , [ {test2:"test1"}, {test2:"test2"} ] }] } ]


Wade
December 31, 2016

re: Strongly Typed Configuration Settings in ASP.NET Core

I noticed a few people talking about hot loading/hot swapping configs in the comments section. Essentially the IOptionsMonitor interface got added, removed, then readded so you can still use this way but it requires a bit of code to get going. Microsoft have also added the IOptionsSnapshot interface though, and this is how they recommend doing reloadable configuration. Instead of injecting IOptions into your class, you now inject IOptionsSnapshot and it will inject the latest settings (At time of instantiation).

That last part is important as if you have a singleton class, the settings won't be "hot swapped" inside it. It's only when the class is built and IOptionsSnapshot is requested from the services collection will it then get the "latest". I wrote a bit about it here : http://dotnetcoretutorials.com/2017/01/01/hot-swapping-custom-configurations-asp-net-core-using-ioptionssnapshot/


John
December 29, 2016

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

Hi sailor! Even though I never mastered to carve while keep planing (I guess I never tried hard enough), your instruction to deploy worked perfectly. Thank you!


Sachin
December 29, 2016

re: Capturing Output from ASP.Net Pages

Does this work in static class as well? As I'm getting assertion failure error. Please help. Thanks :)


Rick Strahl
December 28, 2016

re: Back to Basics: String Interpolation in C#

Thanks @Thomas. I was looking for more info on this and came up blank. Thanks for the link - I've referenced it in the post and added to the post's resources.


Thomas Levesque
December 28, 2016

re: Back to Basics: String Interpolation in C#

You can use String Interpolation with C# 6.0, and any post 4.5 version of .NET assuming you are using the C# 6 or later Roslyn compiler. Although Roslyn can compile down to .NET 4, String Interpolation relies on newer features of the framework to work properly.

There is no such restriction; I used string interpolation in a project targeting .NET 2.0. FormattableString is not necessary in most cases, but if you need it, you can add it yourself, as explained here, or use this NuGet package


Samuel
December 28, 2016

re: Back to Basics: String Interpolation in C#

@Mitul I think what he means is that you can't do something like this

var a = "hello it's currently {DateTime.Now}";
Console.WriteLine($a);

but you could do

var a = "hello it's currently {0}";
Console.WriteLine(String.Format(a, DateTime.Now));

DelegateVoid
December 27, 2016

re: Back to Basics: String Interpolation in C#

Definitely one of my favorite features as well.

For example, it simplifies my go-to byte[] to hex string converter:

 //Sample data var data = Encoding.ASCII.GetBytes("Hello Rick");
//Original version data.Select(b => String.Format("0x{0:X2}", b)).Aggregate((l,r) => String.Concat(l, ", ", r))

//Version with string interpolation data.Select (b => $"0x{b:X2}").Aggregate((l,r) => $"{l}, {r}");").Aggregate((l,r) => $", ");


Rick Strahl
December 27, 2016

re: Back to Basics: String Interpolation in C#

@Grzegorz - thanks for doing my proof reading :-) Guess that will teach me to post at 1am in the morning... I had initially used .ToString() in one of the examples to demonstrate use of methods, but failed to clarify. I've added that in and removed it in the first example. Thanks for the feedback - appreciated!


Mitul
December 27, 2016

re: Back to Basics: String Interpolation in C#

Hi Rick, I use string interpolation everyday and it is a great replacement for string.format. Can you give a small example when you say that, "you can't dynamically load a string with expressions and expect to evaluate the string". I am able to run your Log function in linqpad just fine. Thanks.


Grzegorz Danowski
December 27, 2016

re: Back to Basics: String Interpolation in C#

Please correct String.Format example: string output = string.Format("{0}, you've been here {1:n0} times.") to string output = string.Format("{0}, you've been here {1:n0} times.", name, accesses);

And why do you use ToString in string interpolation? For example, why: var msg = $".NET Version: {Environment.Version.ToString()}" but not simply: var msg = $".NET Version: "


Richard
December 26, 2016

re: External JavaScript dependencies in Typescript and Angular 2

Hi there,

I've been trying to do this exact same thing in my project that uses webpack and I've been unsuccessful. I've installed jquery and toaster with npm, saved it to package.json. I've tried the route of importing and delcar the var as in option one and Ive also tried the provide plugin in webpack config and either way.. cant get this working :( Any help?


Rick Strahl
December 26, 2016

re: Introducing Markdown Monster - a new Markdown Editor

@James - it's something that can be arranged. Post an Issue on Github. It would be an option because I think most people dealing with Markdown do want an editor and preview. But several people have commented that a full screen preview mode would be nice and this suggestion feeds into that.


James M Curran
December 24, 2016

re: Introducing Markdown Monster - a new Markdown Editor

The only thing that MarkDown as a concept really needs is a pure MarkDown viewer. Double-click on a MD file, and a app run showing the fully formatted file (no split screen, no editor), just as when you double-click a .html file is appears in a browser. A toolbar button putting it into split-screen editor mode would make it complete.

So I'd suggest: Run with no file - open into editor Run with file - open into view mode. Run with file and /e option - open file in editor (allows "Open" and "open in editor" on Explorer right-click menu)


Colin Nicholls
December 23, 2016

re: Downgrading a .NET Applications from 64 bit to 32 bit for the WebBrowser Control

Cool post, Rick. It confirms what my gut has been telling me for some time about 32 vs 64 bit apps on 64-bit OS. Unless you need the larger memory space (Sample Libraries in a DAW, for example?) you're often going to have a better experience with the 32-bit version.


Axil Bits
December 21, 2016

re: Error Handling and ExceptionFilter Dependency Injection for ASP.NET Core APIs

Great article. Good information on .net core stuff is hard to come by. Articles like this are lifting the fog on the .net core haze! Thanks Man!


Rick Strahl
December 21, 2016

re: Visual Studio Debugging and 64 Bit .NET Applications

Absolutely right Ralf. Fixed. Thank you.


Ralf
December 20, 2016

re: Visual Studio Debugging and 64 Bit .NET Applications

Hi,

One of them is that the host process will default and stick to 32 bit even if the Prefer 32 bit option is checked.

This doesn't sound right to me - was it meant to say

One of them is that the host process will default and stick to 32 bit even if the Prefer 32 bit option is not checked.

Regards, Ralf


Roland
December 19, 2016

re: A WebAPI Basic Authentication Authorization Filter

Neat. This should be pushed into the official .NET code as quite a few people are asking about this on stack overflow etc.

Thanks a lot for posting this up, saved me a lot of time and gave me a good example to build on further. I made the following changes to allow basic auth to be used on a Web API 2 using the standard user database.

    public ApplicationUserManager UserManager => HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();

    protected virtual bool OnAuthorizeUser(string username, string password, HttpActionContext actionContext)
    {
        if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return false;
        ApplicationUser user = UserManager?.FindByEmail(username);
        return user != null && UserManager.CheckPassword(user, password);
    }

ttm
December 19, 2016

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

One important question (at least for me): is this applicable only for Asp.Net Core application or it is the way to go for Asp.Net Core Application referencing v4.6.1 Framework?


dragon788
December 16, 2016

re: Automating Installation Builds and Chocolatey Packaging

Psake is pretty good but has a slightly arcane syntax. Somebody in the ChocolateyGUI Gitter channel mentioned Invoke-Build as a much nicer PowerShell based task runner, though they were actually using Cake due to their familiarity with C#.