It’s been a while since the last Community Update. I would like to apologize. I rewrote the system that generate the content and lost some content in the process. A few lessons learned on that one.
privatestatic IEnumerable<QueryStringParameter> ExtractParameters(string query) { string withoutQuestionMark = query; if (withoutQuestionMark.IndexOf("?", StringComparison.Ordinal) == 0) withoutQuestionMark = withoutQuestionMark.Remove(0, 1); if (!string.IsNullOrWhiteSpace(withoutQuestionMark)) { string[] nameValues = withoutQuestionMark.Split('&'); foreach (var nameValue in nameValues) { var pairSplitted = nameValue.Split('='); if (pairSplitted.Length == 2) yield return new QueryStringParameter(pairSplitted[0], pairSplitted[1]); } } } }
So what does this code do? It exposes 2 methods. One for filtering and the other one to generate a string id that will look very similar to a GUID. The filter will reorganize the query string by alphabetical order and remove any “utm_*” from the query string. Those parameters are normally used in Google Analytics Campaigns and will only add noise to our data. They can safely be stripped out.
As for generating the ID, I just generate an MD5 hash which I convert into hexadecimal without separators.
Hey everyone. Hoped you all had some nice Christmas vacation. The return of the community update has lagged a bit as I rewrote some part of the application that generate those links.
I will share my process on Github eventually. If you are in a hurry, you can always email me through http://maximerouiller.com
ElasticSearch is a Java-based service that will allow you to stock data and query that data. If you know about Solr, the tool is in the same spirit but with a different management model. If you don’t, you might know Lucene or Lucene.NET. ElasticSearch is a server implementation of Lucene. Among the great feature of ElasticSearch is how it reaches high availability through a proper node scaling. Mostly, you won’t have to do anything by default. Everything will work straight out of the box.
For the full list of feature, I will redirect you to their website.
System requirements
Latest Java version
Installing Java
First, we’ll get Java out of the way. If you don’t have java installed on your machine, go to Ninite.com and select the runtime “Java” and proceed with the installation.
Once this is done, you have to set your JAVA_HOME which for whatever reason is never set after installing a JRE. If you need help on how to set your environment variable for your Java JRE, Stackoverflow is filled with such answers.
To ensure that it works, open a command prompt and type “java” and press enter. It should display the help prompt for the Java command line utility.
That’s it. Now we are ready to install ElasticSearch.
Installing ElasticSearch
First, we’ll start by going to ElasticSearch.org to download the latest release (0.90.8 as of this post). They release fairly often so you might want to keep yourself up to date regularly.
After downloading the ZIP file, you will see something like this:
Inside thebin folder, you will have a file called elasticsearch.bat. Double click and you are done.
A command line will be opened and your instance will be available.
What do we have now?
First, if you hit http://localhost:9200/ with a browser, you will see a health status of your ElasticSearch instance with the version number, the name and more.
If you want to see everything that compose your ElasticSearch cluster (a cluster is defined by default even for one node), you can hit this url: http://localhost:9200/_status?pretty=true
However, if you are from the .NET world like me, you’ll want some abstraction over that tool so that you don’t have to deal with everything at a granular level.
Tools
For .NET, I recommend NEST (documentation). It provide a great abstraction with .NET 4+ support for controlling an ElasticSearch cluster.
If you want to get down to the metal, I recommend the Sense Extension for Chrome. It comes with intelisense and will allow you to do most of your maintenance through it.
Conclusion
So I just wanted to get this out of the window. ElasticSearch is very easy to install and get started. I’m currently working on a curation tool that allows me to store lots of data from Twitter and other sources. This is what is bringing you the daily Community Updates. This tool is currently running on my station but is heavily using ElasticSearch to sort through the content at blazing speed.
Eventually, I want to get that code out in the open. However, I know that people will question on how to get ElasticSearch ready hence why I created that post.
Well Christmas is coming and it shows. Not a lot of people are actually posting new content.
First there is the December release of Ajax Control Toolkit that you should checkout if you are using WebForms. Then, there is Part 10 of the tutorial. You should checkout the rest of the tutorial which can be found within the post. Finally, an MSDN article about CORS support in WebAPI 2.
NOTE: As an MVP, I have a licence for ReSharper that is provided for free by JetBrains. However, I am not paid by JetBrains for this post. I just love the tool and want to keep you guys updated.
This week is purely ASP.NET. I’ll keep this short and sweet but everything down here is worth taking your time for a slow read on the train/metro/bus back home.
Then I suggest that you take it easy for the weekend. Christmas is coming and you’ll all need to relax before partying.
Very interesting content today. Howard Dierking released a RC1 of the OWIN static file middleware. If you are using a previous package, you want to upgrade now (and don’t forget the pre-release flag).
Ever wanted to log your JavaScript output to the database for further inspection? Maybe you have a Single Page Application and you need error on the JavaScript side to be logged to the server? JSNLOG is there for you! Check it out!
If you are using F#, new templates are now available for download. Don’t miss out on the new templates for WebAPI, MSTest as well as Nancy.
Finally, if you are still missing out on the new vision of ASP.NET (a.k.a. One ASP.NET), you will want to read the article dedicated to that. A must read!
Finally, Imran Baloch deliver us a barebone implementation of the new Identity component for ASP.NET. I should have to say it again but… it’s also a must read.
Not too much content but some very important one. Let’s start with the fun stuff first.
We have a nice tutorial on how to write OWIN middleware by OdeToCode. Then we have the OWIN ASP.NET Identity package for Entity Framework. Also in the news, the official blog post from MSDN about the latest Release Candidate of ASP.NET MVC 5.1, Web API 2.1 and Web Pages 3.1.
An oldie but a goodie, how to change where the ResourceManager get its strings. The last article got you covered.
Finally the most most important one is the ASP.NET December 2013 security updates. This is a MUST READ. One very important note that I will copy/paste is that EnableViewStateMac is going to go deprecated in future version of the .NET Framework. If you are relying on it for your websites to work, you must take time to fix it as soon as possible. No time to snooze on this one.
Important note: The next version of ASP.NET will forbid setting EnableViewStateMac=false. Applications which set EnableViewStateMac=false may no longer function properly once this update is pushed out. Web developers must take this time to ensure that their applications do not set this switch to an insecure value.
A lot of new content today. Web API 2.1, MVC 5.1 and Web Pages 3.1 goes in Release Candidate. Don’t miss a nice article on how to properly upgrade a project from MVC 4/Web API to MVC 5/Web API 2. Ever needed to build a custom Identity database? Lookup the link to Codeplex for a SQL Project that does just that. Rick Strahl show off the Helios performance test while John Papa dispel some myths about single page applications.
Finally, don’t miss on Entity Framework 6 which has been nicknamed “The Ninja Edition”.
OWIN is a new way to build application. With or without the normal IIS server. To retrieve the original description from OWIN.org:
OWIN defines a standard interface between .NET web servers and web applications. The goal of the OWIN interface is to decouple server and application, encourage the development of simple modules for .NET web development, and, by being an open standard, stimulate the open source ecosystem of .NET web development tools.
Four layers are present. The Application layer, the Application Framework layer, the Server layer and finally the Host layer.
The Application layer is where your code will end-up. The Application Framework is where you will find something like WebAPI and ASP.NET. The Server Layer will represent what is currently handling resource for your server (think connections pool, thread and what not). As for the Host, it’s the technology that will be hosting the whole stack. In this case we have 3 choice. Either it’s IIS, Katana.exe (Microsoft implementation of OWIN) or simply a self-hosted console application that listen on a web port.
Here’s what it looks like in a nice diagram:
Simply, why should I care?
What is great with OWIN is that you only import what you need. Do you need to serve static files (images, javascript)? Yes? Import the module that handle static files. Do you need Facebook OAuth? Import that too. You have to look at all the features that you application might use and see this as a buffet. You will need many of them but you don’t need everything. What about Google OAuth? Don’t need it? Perfect! It’s not included by default.
The most default application that you can do will literally just listen to a port and return string content without a response type. Here’s what it looks like:
This application won’t support login, WebAPI, cookies or even directory browsing. It only returns “Hello, world.” for each and every request. This will lead to very low-memory processes and a highly specialized task of returning “Hello, world.”. However, since we are not writing so simple app, we will need to add support for Web API, routing and maybe even authentication. How do we do this? OWIN defines a way that to specify all this. It’s called the Middleware pipeline.
The OWIN Middleware Pipeline
So let’s take the base application. We created a truly empty web application with Visual Studio 2013 and we added the OWIN startup class as described above. How do we add WebAPI in here?
First, we add the package Microsoft.AspNet.WebApi.Owin to our web project. Then we are going to add before what we already have the proper configuration to use WebAPI 2.
1 2 3
var routes = new HttpRouteCollection(); routes.MapHttpRoute("Default", "{controller}/{id}", new {id = RouteParameter.Optional}); app.UseWebApi(new HttpConfiguration(routes));
With this, we the equivalent of a default WebAPI route. Let’s add a default controller to our system by using “Add New Scaffolded Item” and Empty Web API 2 Controller.
Let’s make a default method to return some random data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
publicclassOwinController : ApiController { public OwinItem[] GetAll() { returnnew[] { new OwinItem{Id = 1, Name = "First of them"}, new OwinItem{Id = 2, Name = "Another one of them"}, }; } }
publicclassOwinItem { publicint Id { get; set; } publicstring Name { get; set; } }
Hitting our URL from the default URL will return the default Hello World. However, hitting your WebAPI with /owin instead will return our fake data and will answer with XML/JSON depending on your HTTP Headers.
Isn’t that cool? We only imported what we needed for that project and nothing more. If you are looking at the Nuget feed for “owin” (like here) you will see that a lot of packages has been created. They are all useable by the same patterns. You can basically build your application up from scratch by buying only what you need.
Pipeline Order
What happens if we invert the UseWebAPI and the Run(…) command? If you try it, you’ll see that nothing else register to WebAPI anymore. The Run element will actually catch everything else that is not handled by a middleware (WebAPI). The Run at the end might be useful if you want to catch any potential request that goes through the .NET pipeline and that isn’t catched.
OWIN Hosts
Many hosts are available. As of right now, you should still use IIS. However, Katana.exe can be used to host your website or you can simply self-host it within a Console application. As more hosts are being supported, we’ll see greater support for Mono in those scenario.
Why should I use OWIN?
Well first there is a lot of cleaning that has been done around which DLLs are actually needed to run a web project. IIS is slowly being geared toward greater support for OWIN with the IIS Host instead of the SystemWeb host. As things are moving forward, you will see more and more OWIN development coming in to Visual Studio and your everyday project. OWIN will allow us to build great web software with only the things that we need.
No more will we have to get stuffed with useless DLLs and be stuck by what Microsoft provides out of the box. As things are moving forward, we’ll be able to easily swap parts of the framework so that we can respond quickly to ever changing web. OWIN by itself isn’t meeting all of its promises yet as for what is currently implemented. But as Microsoft and the community moves forward and continue to build great middleware for OWIN, we’ll get access to even more features and be even more nimble than we could ever be before.
I’ll leave you with a list of links that I think you should read.
Here is what we have for the community. First, a great warning from Levi Broderick about how medium trust is dead. This link will bring you to a KB from Microsoft that will give you all the details you need to know about that.
Then we have a nice tutorial from www.asp.net that will show us how to use external authentication services. Sam Jenkins show how to implement Two Factor Authentication in ASP.NET MVC.
Finally, did you know that JSON.NET allows you to convert XML from and to JSON? Check it out.
Not a lot of content as for every Friday, but we got a few that is very interesting.
Profiler or debugger, output caching or per-controller configuration… it’s all bellow. Do not miss the last one on securing ASP.NET Web API with Windows Azure Active Directory with OWIN.
So what do we have here? A very clear explanation of what is OWIN by Robert Muehsig (MVP). It’s a must read to finally know what OWIN is all about. Then there’s some way to optimize your MVC with Azure caching and compiled views and finally, we have an amazing multi-part tutorial on WebAPI. Don’t forget to scroll at the bottom of the article to see the other parts.
As for the tooling, we have Superscribe which is a routing framework that is OWIN-compatible and a small JavaScript tool that allow you to do client-side cropping (with CSS) with the correct data to do a proper server-side cropping. Perfect for cropping user profile pictures.
So after a long weekend a few skipped days to relax, I’m coming back with more links!
First, if you are following OWIN, a new release of the OWIN IIS Host has been released. Still in pre-alpha but hey, it’s there! Then there’s two excellent articles on Cross-Origin Resource Sharing (CORS) to read that I would suggest personally and finally, 2 more post about Web API.
That’s for today. I’ll find you some more tomorrow.
So I’ve skipped a few days to see what would come up. It was well worth waiting. First, Dominick Baier from LeastPrivilege.com did two more parts for his Web API Identity dissecting. Then Jerrie Pelser from BeARockStar.com wrote a Yahoo, LinkedIn and GitHub OAuth provider for OWIN. If you needed those, they are right bellow up for grabs!
Then Brock Allen did an awesome post on OWIN Cookie Authentication. A must read!
Finally, I included a project for F# OWIN support as well as a nice comparison of advantages/disadvantages of each web technology we have in the .NET world (made by Microsoft). As a cherry on top, I included a link by Imran Baloch (ASP.NET MVP) on how to do page instrumentation in .NET 4.5.
So during the weekend, there was a bit of everything. There is a nice introduction on how to debug OWIN apps as well as playing with the new OWIN on IIS layer that is demoed by Rick Strahl. As for the new ASP.NET Identity mechanism, Olav Nybø goes over the new features and explain the structure and logic behind the new system while Abhimanyu Kumar Vatsa explains how to customize it to your needs.
If you are more interested in WebAPI, there’s a nice tutorial on how to build proper action filters for async methods as well a dissection of WebAPI Individual Accounts Template.
I’m hoping you’ll be enjoying this reading list for today.
Among the different things that grabbed the community interested today were pretty much all about ASP.NET.
We have two video links (Thanks Channel 9!) that shows the integration of Bootstrap in the latest release of MVC as well as the authentication using the new Identity system. If you are a fan of WebAPI, don’t miss out on the batch support in WebAPI 2 as well as how to unit test a controller.
I hope you enjoy this small bundle of links for today!
Most of the developers I know are actually very passionate about what they do and choose the best tool for the job. Sometimes this means that you use Microsoft tools and sometimes, you use open source.
If you are interested in giving back to the community, a website has been established to list all the projects that has simple bugs and/or features that are not assigned to anyone and are… up for grabs.
From Glimpse to Octokit.NET wihout forgetting NuGet, you can find all those list and more right here.