Recent Comments



Rick Strahl
Today

re: <main> HTML5 Tag not working in Internet Explorer 9/10/11

@Henrik - it can be forgiven for IE 9, but not for IE 10 and 11 which claim to be HTML 5 compliant where those tags are not 'unknown' tags - these are bonefide HTML elements.

And again it doesn't really matter that IE might interpret the spec differently - the fact remains every other vendor got this right EXCEPT for IE which is enough reason IMHO that it should work the same especially given that IE has always been lagging the standards behind other browsers so the implmentation has been well known beforehand.

B
Yesterday

re: Using Let's Encrypt with IIS on Windows

Renewals
LetsEncrypt-Win-Simple also includes an interface to renew all certificates easily. You can run:

LetsEncrypt --renew
and it checks all sites it's managing for expiration dates and if expired (or on the day of expiration) it automatically renews and replaces the old cert with a new one. Nice!

The utility also creates a scheduled task that runs this command once a day and fires update requests. Note you might have to tweak the task User Identity settings as described here to ensure that the user is logged on properly when running the scheduled task.


The problem is I cannot find any LetsEncrypt scheduled task, should I create one, and which application should I choose?

Henrik Vendelbo
Thursday

re: <main> HTML5 Tag not working in Internet Explorer 9/10/11

This is correct behaviour. Unknown tags are treated as inline. It is a sensible default. The main tag is a recent addition so you should forgive IE for not knowing it. You should have this in your reset stylesheet;

/**
* Add the correct display in IE 9-.
* 1. Add the correct display in IE.
*/

figcaption,
figure,
main { /* 1 */
display: block;
}

- ref: normalize.css

Omu
Thursday

re: Upgrading to ASP.NET Core RTM from RC2

the camel case thing is a big facepalm, think it was a decision that was not made based on logic, but rather on "coolness"
if you look here https://github.com/aspnet/Mvc/issues/4283
the main argument for the change is the current Date
also given the amount likes, it shows why democracy doesn't work :D

Rick Strahl
Tuesday

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

@Chris - the second commented call was meant to demonstrate that you can serve Razor pages from any location in your wwwroot application. So ~/helloworld.cshtml can sit in the /wwwroot folder of your project and get served. Note that this only works if the Content Root is set in program.cs (which is why I was originally experimenting with this code as it wasn't working withtout the content root set).

Chris Harrington
Tuesday

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

Hi Rich,
I see this code in controller
return View("helloworld");
//return View("~/helloworld.cshtml");
but nothing in your article explaining that second commented-out call.
I wasn't able to get either one to generate output.

Could you also elaborate on : "ASP.NET Core MVC uses standard View discovery logic by default, so it’s looking in the /Views/Helloworld folder for a HelloworldMvc.cshtml view. " I'm assuming that you didn't demonstrate this in your code. But again, I couldn't get any of the views to render.

Surinder
Tuesday

re: JavaScript JSON Date Parsing and real Dates

Thanks for this informative post. Currently I am working on an application and I need to pass Java 8 LocalDate from MVC controller to Ajax response in Jquery Data tables. I did not find anything to deserialize Localdate JSON string back to LocalDate in UI. So I manually had to append year, month and day to build date.
Is there a better way to handle Localdates in such siituation.

Please let e know, I will get rid of messy code in JS file I wrote. Below is my sample code columnDef column

columnDefs : [ {
targets : [ 6 ],
render : function(data, type, row) {
/* var json = JSON.stringify(data);
var date = JSON.parse(json);
console.log("json: " + json + "date : " + data); */
var month = data.month;
var day = data.day;
return data.year+"-"+month+"-"+day;
}
}

Billa
Tuesday

re: .NET WebRequest.PreAuthenticate – not quite what it sounds like

Nice Article! Got more information on why there are two requests?

Is there a way to reset NTLM credentials and force to fall over? I tried but somehow its always sending the credentials. I am not sure is it default cached.

Explained the issue at http://stackoverflow.com/questions/38357792/set-network-credentials-via-config

Ed
Tuesday

re: Updated DeleteFiles Utility now on Chocolatey

Is there a limit to the -d parameter? I am trying over 800 days and it isn't deleting those files.

re: ASP.NET Routing not working on IIS 7.0

I had this problem as well... I used the standard web project in VS 2015.
Thanks a lot you saved me many hours by your great blog post!

Rick Strahl
July 17, 2016

re: Rendering ASP.NET MVC Views to String

@Travis - Razor encodes all expressions by default. If you want raw HTML strings you have the use the @Html.Raw(yourExpression) to get the raw unexpanded text to be rendered.

Travis
July 16, 2016

re: Rendering ASP.NET MVC Views to String

Hi Rick.

Thanks for this Class. Just a quick question:

I have a 'Basic' view template (using Razor) for a basic email. It contains a bit of html jazz an then @Model.EmailMessage (to substitute my message). I then populate like so:

var EmailModel = new BasicEmailViewModel()
{
    EmailMessage = "(Message from: " + model.Name + ")<br><br>" + model.Message
};
 
string messageBody = ViewRenderer.RenderView("~/Views/Emails/Basic.cshtml", EmailModel);


It works great. However the "<br><br>" tags display in the email as "<br><br>" instead of 2 line spaces. It's as if they are being HTML encoded. Is there any way to add some basic HTML formatting like this and not encode it when I render the view?

Hope this makes sense! Thanks!

Ammar
July 16, 2016

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

@Rick - Thanks for the quick reply Rick. Indeed .net apps always run out of the current folder. Got a bit confused due to the problem that appsettings.json was not found. This project originally was created with RC1, migrated to to RC2 and then to RTM. I ran another project that was created fresh with RTM and it is worked fine. I compared all the configuration files and found everything same but still the first app did not work. I then opened the xproj file and replaced all "dnx" lines with "dotnet" ones copied for the new project and it all started working. Will dig more into it later.
Just mentioned it here so that someone else could save his/her time :)

Rick Strahl
July 16, 2016

re: Hosting SignalR under SSL/https

@Junaid - if you create a self-signed certificate that certificate is valid only on the machine that you created it on - unless you register that certificate on other machines. You can do that by installing the certificate on remote machines as shown in the Copy Certificate to Trusted Root section in the post above. You can do the same on other machines that you want to trust.

If you want a certificate that 'just works' on machines then you have to use a certificate authority signed certificate from a full CA. These days you can use Lets Encrypt to create these certificates for IIS and then use them in your SignalR appplications. For more info see:

* https://weblog.west-wind.com/posts/2016/Feb/22/Using-Lets-Encrypt-with-IIS-on-Windows

and

* https://weblog.west-wind.com/posts/2016/Jul/09/Moving-to-Lets-Encrypt-SSL-Certificates

Rick Strahl
July 16, 2016

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

@Ammar - .NET Core Apps run out of the current folder that they are launched from, which is the same way .NET applications (and any Windows application for that matter) have always worked. If you want a different path and you want to control the path then you have to change path to that location. Path.SetPath() should work, along with looking at the executing assembly. .UseContentRoot() simply sets the path you provide it which in your code is the startup folder where you launched from.

Rick Strahl
July 16, 2016

re: Moving to Lets Encrypt SSL Certificates

@GFW - I ended up with Certify because there's nothing to set up or configure and to be honest I like to run a GUI where I can easily see what's set up. However, Win-Simple works just fine as well, and is also very easy to start with, but it's not quite as easy to see what's set up and configured. Last I looked too it wasn't very clear how to remove sites or force an immediate renew. That may have changed by now though.

Basically it comes down what you prefer: Command line tooling or something a little more visual that you can use interactively.

Gfw
July 15, 2016

re: Moving to Lets Encrypt SSL Certificates

Question...

What made you choose Certify over Win-Simple? I had issues with Certify when I initially started so I went with Win-Simple on about 8 websites. The automatic renewal feature works great.

BTW... great articles on LetsEncrypt, it was your first article that got me started.

Ammar
July 15, 2016

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

Hi Rick,
I am trying to run an asp.net core app on Linux and Windows but it throws up saying appsettings.json not found. I figured out that if i run the command like (in windows):
C:\Users\Dev> dotnet C:\MyProgramFolder\MyProgram.dll
it sets the ContentRootPath to C:\Users\Dev which is obviously not what I want.
The program.cs contains the usual .UseContentRoot(Directory.GetCurrentDirectory()). How do we handle this?

Junaid
July 14, 2016

re: Hosting SignalR under SSL/https

I have developed a portable, self hosted windows service(SignalR), by portable i mean that any user who wants to communicate/upload the data to my web app should install this service on their local system. There was no problem communicating over HTTP. I followed all the steps provided in this blog to make it work over HTTPS. It works fine when the windows service and the web application are hosted from the same system. But it fails to communicate over HTTPS(using self signed certificate) when the service is hosted from a different machine and throws up error ERR_INSECURE_RESPONSE, though i could notice that the signalR proxy is generated.
What kind of SSL certificate do i have to create to distribute to multiple clients to communicate. How do i register the SSL certificate in local system and communicate over it. Any pointers over this will be of great help.
Thanks in anticipation.

Sapan Desai
July 12, 2016

re: Strongly Typed Configuration Settings in ASP.NET Core

Hi Rick, Nice post. Thanks. I am wondering how I could make use of this feature in my unit / integration tests where there is NO application Startup.cs. One way that I am trying to do is as follows (below code is straight out of one of the unit / integration test methods):

var settings = Options.Create(new ProductApiSettings());
var productAPIUrl = settings.Value.ApiUri;

But during the test execution, when I look at the value of "productAPIUrl", it is still null. Even though I have an appsettings.json file as follows:

{
"ApiUri": "http://<<productAPI URL>>"
}

Ted
July 12, 2016

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

Thanks Rick. Great Article (as are many of your other posts)!

Do you know if it is possible to host two web sites on IIS (on the same server) and have the ASP.NET core site use a port other than 80? I have two web sites one asp.net 5 and one .net core and if I switch the asp.net 5 site to a different port (8080) and use port 80 for the .net core site both sites work fine. If I use port 8080 for the .net core site (and 80 for the asp.net 5 site) when I browse to the .net core site I get an error that "The site cannot be reached".

Serj
July 11, 2016

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

Saw this article mentioned on the ASP.NET community stand-up. Good stuff. I know understand how the .Use .Run work.

Mike Hillman
July 11, 2016

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

Thanks. You have a gift for explaining the technical.

Felix
July 10, 2016

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

Thank you - this article puts together many things that we guessed using "trial and error". There are still several things that are puzzling. As somebody mentioned, WebDAV publishing to the server isn't yet available, and simply publish to local directory and copy to remote server doesn't work because many DLLs are locked. So, one needs to stop the site, then copy files, then start again. A few other idiosyncrasies like that.

However, the biggest problem that I can't find any guidance is virtual directory support (not app in virtual directory, but virtual directory inside the app). We had a pointer to UNC path that contained picture gallery. Short of moving gigabytes of data to IIS server, I can't figure out how to do that...

If anybody knows some post that explains it - I would greatly appreciate the pointer

Dan Kellett
July 08, 2016

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

This was extremely helpful. Thank you.

jeremy c.
July 08, 2016

re: Upgrading to ASP.NET Core RTM from RC2

All I had to do to upgrade my asp.net RC 2 project to asp.net RTM was in my project.json

1. replace "-rc2-final" to " "
2. replace "preivew1" to "preview2"
3. and finally change your Microsoft.NETCore.App to:

"Microsoft.NETCore.App": {
"version": "1.0.0"


That's all folks!

Giuseppe
July 08, 2016

re: Strongly Typed Configuration Settings in ASP.NET Core

Hi all, @Rick. Your implementation from this post used to work in my team project on RC1. Now we're migrating to RTM and we find the following issue: 'configuration.GetSection("someTopLevelKey")' returns null. When I try 'configuration.GetKey("someTopLevelKey:propertyKey")' the value is returned, so configuration source are set correctly (thanks to 'SetBasePath()' too).

Besided that method, there used to be also a 'configuration.Get<SomeConfigClass>("someTopLevelKey")' which is not there anymore. We tried replacing with 'GetValue<>()' and it returns null as well.

Does anyone know how to grab a whole section of e.g. appsetting.json, and map it to correspondent strongly-typed POCO configuration class?

TA

Saravanan
July 07, 2016

re: ASP.NET MVC, Localization and Westwind.Globalization for Db Resources

Hi Rick,

I have a question like how to maintain the user level language in Global file?

#My Scenario

User able to select the language while creating a account and login to the respective account application will run based on user selected language. How to maintain the above scenario in Global.asax file. Please advice me how to do that.

Thanks,

Saravanan

Vitaliy
July 07, 2016

re: Strongly Typed Configuration Settings in ASP.NET Core

Hello, @Rick. You can look at my solution for autoreload strongly typed configuration at http://net-nts.blogspot.ru/2016/07/autoreload-strongly-typed-configuration.html

bloumoord
July 06, 2016

re: Updating Assembly Redirects with NuGet

Is there a command line version of this?
I use this command to update packages in my solution, but found that binding redirects in web.config / app.config files are not updated as it would be when updating in VS Package Manager Console
"nuget update mySolution.sln"

Rick Strahl
July 06, 2016

re: Prettifying a JSON String in .NET

Easiest probably to use highlight.js. Above in West Wind WebSurge I'm using AceEditor.js.

Dan
July 06, 2016

re: Prettifying a JSON String in .NET

After you formatted the JSON response, how did you do syntax highlighting?

rahul agarwal
July 05, 2016

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

Thanks Rick !!! One more quick thing, CLR itself is COM component and is specific to Windows. In this sense, is CoreCLR different ?

Also for MONO, is different runtimes required for different platforms.

Thanks!!

Rick Strahl
July 04, 2016

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

@rahul - that's the way it's always worked with the JIT. In theory that was always possible and has been with Mono - you could run Windows compiled assemblies on Mac and Linux with Mono before - as long as you didn't stick Windows specific dependencies from the FCL into your code.

The runtime determines the execution environment that is platform specific, and the assembly code calls into the platform specific APIs that the runtime exposes for things like file access, network access and system resources like the environment etc.

With .NET Core you will eventually also be able to compile to native code by explicitly specifying your platform target which gets you a native binary. I think that works today with UWP executables (which is Windows only but you can get native, fully compiled binaries).

rahul
July 04, 2016

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

hi Rick,

I always loved your article and found you opening the nuts n bolts of internal systems.

One thing which is still kind of magic to me is : how coreclr is designed to target multiple OS ? Does Jitter uses conditional compilation to produce native code at run time ( meaning if target platform is MAC OS then run some MSIL else run some other MSIL for windows platoform ) ? As I know full CLR makes use of Win32 APIs for resource allocations ( like threads ) - how does CoreCLR address all this cross platform.

Could you please help me understand this !!

Thanks!

Kris
July 02, 2016

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

Finally I have managed to run ASP.NET MVC using .NET Core on linux. Great, easy to follow article.

Rob
July 02, 2016

re: Upgrading to ASP.NET Core RTM from RC2

Another note: EntityFramework introduced some breaking changes to the Scaffolding that might cause issues for anyone without fully camel cased tables.

https://github.com/aspnet/EntityFramework/issues/5947

There is a gist sample on that thread with a work-around.

Dan Harner
July 01, 2016

re: Upgrading to ASP.NET Core RTM from RC2

I had the same problems with Visual Studio after installing the Preview Tooling, but all I needed to do was to remove the contents of my C:\Users\<your users name>\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache folder as per this SO answer: http://stackoverflow.com/a/31918711/147418

Rick Strahl
June 30, 2016

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

@Brad - thanks for catching the missing `dotnet restore` calls whenever a library is added. I've added those into the post.

Brad Falk
June 30, 2016

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

@Lee After converting it to a web app you have to do a dotnet restore, before the dotnet run. This will pull down the AspNetCore related dependencies.

This is a great article Rick, thanks for this.

Spencer Bench
June 30, 2016

re: Creating a dynamic, extensible C# Expando Object

@dd: I don't think so. At least, not in the way you're illustrating. In lambda expressions, "this" is a captured variable. For example:
public class MyClass {
 
    public void MyMethod() {
        dynamic d = new SpecialDynamicObject();
        d.xyz = true;
        d.SpecialMethod = () => {
            return this.xyz; // Won't compile; "MyClass" has no member "xyz"
        };
    }
}

The "this" keyword in the body of the lambda expression refers to the enclosing MyClass instance, not the local variable d. If you need to refer to d instead, you could do something like this:
d.SpecialMethod = () => {
    return d.xyz;
};

Rick Strahl
June 30, 2016

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

@Mike - you can't run ASP.NET Core without Kestrel - Kestrel is THE web server that everything runs in. IIS is just a proxy front end as is something like ngnx on Linux. AFAIK there are no other hosts at the moment and I don't think you'd want another host really since Kestrel is highly optimized. You can embed Kestrel into other .NET Core apps so there should be very little need for something else.

Mike Gale
June 30, 2016

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

Thanks for sharing your explorations. I was initially dubious about this approach, but this article has changed my mind.

Have you explored changing a Kestrel site to a pure IIS site (without the proxying)?

Brian Federici
June 30, 2016

re: Upgrading to ASP.NET Core RTM from RC2

Thank you, Rick. In addition to uninstalling the items you mentioned, I also had to go through the Windows Registry and delete any items that contained ".NET Core" in them. That was the only way I could get the Web Tooling Preview 2 to behave with VS 2015 Update 3. Figured I'd mention it in case it helps anyone else.

Rick Strahl
June 30, 2016

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

@Lee - not sure why you would get that. Make sure you are online (the references are coming from NuGet after all) and that you have to the right target selected. Can you clone the project from Git to see if that works for you, and if it does compare what you find? Post back here if you find out what went wrong.

@Bertrand - thanks. Yup didn't know you could generate an Exe. I'll check it out and ammend the post later today.

Nicholas Petersen
June 30, 2016

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

That was excellent Rick, thank you.

Bertrand
June 30, 2016

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

Great post as usual, thanks Rick! In "where's my exe", you missed that you can actually get an exe if you target a specific runtime. See https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/index

Roman
June 29, 2016

re: Web Browser Control – Specifying the IE Version

Hello Rick,

Nice article! However, I stumbled upon a weird use case when changing the registry keys didn't really help.

I am one of the devs for a communication tool, that among other features has an option to set up Windows screensavers. Thing is, these screensavers can contain HTML content, and I really wanted to render it in modern browser, like IE11. So I went through, added required keys and words in local_machine and current_user, adding the rules for screensaver our software generates.

The result is - if I just go on and launch the screensaver manually (by executing .scr file) - it renders in emulated IE11. If I go to screensaver settings and use the "Preview" function - it renders in emulated IE11. However, when the screensaver is launched by the system itself - it still draws all the stuff using IE7.

I was wondering if you might have any insight on what else should be changed for this to work. I tried adding usual Windows scrnsave.exe utility and our application itself to the browser emulation rules list, to no avail.

Regards,
Roman

Lee
June 29, 2016

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

Everything worked until I tried to convert it to a web app. I updated my project.json file as mentioned above. However this gave the error:

"The dependency "Microsoft.AspNetCore.Server.Kestrel >= 1.0.0 could not be resolved."

Do you know what I may have done wrong?

Rick Strahl
June 29, 2016

re: GZip/Deflate Compression in ASP.NET MVC

@Fixbug - if you're using any error filters or ASP.NET global error handlers you should ensure that those are removing Response.Filter - this is good practice regardless of this implementation. Otherwise use an exception handler on the controller to remove the filter if there's an unhandled exception. I guess we could probably add that to this filter implementation to automatically remove compression.