Skip to main content

Posts

Caching HTTP Handlers

There comes a time in an ASP.Net developer's life when he must write own HTTP handler. Quite often the handler has to return a static or a rarely changable content and the developer should implement caching of it. Step 1. Specify how long data should retain cached. Someone does it this way: context.Response.Cache.SetExpires(DateTime.Now.AddDay(1)); Someone likes this approach: context.Response.Cache.SetMaxAge(86400); //1 day in seconds The most careful developers use both: context.Response.Cache.SetExpires(DateTime.Now.AddDay(1)); context.Response.Cache.SetMaxAge(86400); All the above are correct in their own way. The first example sets an absolute expiration date. In the list of headers it looks like this: Expires: Mon, 25 Jul 2016 19:50:09 GMT This header was introduced in the HTTP/1.0 specification but it is supported by HTTP/1.1 too. A small pitfall related to this header is that the expiration date and time are set explicitly and it may cause issues ...

JIRA REST API: Cookie-based Authentication

Three authentication methods are proposed by the JIRA REST API documentation: Basic Authentication is a simple but not very safe approach. Credentials are sent in the header on every request and encoding to Base64 is not a proper protection in this case; HTTPS connection is required. OAuth authentication - looks a bit complex and requires additional configuration at the JIRA server that is not always possible. Cookie-based Authentication - this approach seems to be the most convinient one: credentials are checked once, then the authentication cookie only is sent on subsequent requests. However, trying to use the cookie-based authentication I encountered an issue. The approach described in the documentation worked partially: I was able to create a new session and get the response containing the session cookie but all subsequent requests using this session cookie were rejected as unauthorized. Spending some time investigating this I found the cause of the issue: JSESSIO...

JSON Viewer. Part 2

JSON Viewer extension has now a few new features: ability to print formatted data ability to format input data keeping JSON markup ability to compare 2 JSON data Source code and binaries to download are here: https://github.com/marss19/json-viewer-visual-studio-extension After installation the viewer appears in the main menu: Tools -> JSON Viewer. Applicable to VS 2012 and 2013. UPDATE The source code has been migrated to GitHub: https://github.com/marss19/json-viewer-visual-studio-extension The latest release is available for download in Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=MykolaTarasyuk.JSONViewer

JSON Viewer

Made a simple extension to Visual Studio to view JSON data in a more user-friendly format. Source code and binaries to download are here: https://github.com/marss19/json-viewer-visual-studio-extension . After installation the viewer is available in the main menu: Tools -> JSON Viewer. Applicable to VS 2012 and 2013. Please note that custom VS extensions cannot be installed into Express editions of Visual Studio due to a Microsoft policy. UPDATE The source code has been migrated to GitHub: https://github.com/marss19/json-viewer-visual-studio-extension The latest release is available for download in Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=MykolaTarasyuk.JSONViewer

Not So Primitive Types

A few nuances about the primitive types in .Net which are not so obvious: If you add two short s you will get int . The same with byte s. Arithmetic operators for these types are not implemented in .Net therefore the values are implicitly converted to int before calculation. short x = 2, y = 2; var z = x + y; Console.WriteLine(z.GetType()); //output: System.Int32 Chuck Norris is not the only person who can divide by zero. Every .Net developer can do this. Just use floating point numbers. var z = 1.0 / 0; Console.WriteLine(z); //output: Infinity

Bulk Generation of Tasks in TFS

It usually took me hours to add all tasks for my team for the next sprint in TFS. Existing UIs for this purpose were too sl-o-o-o-w, both built-in Team Explorer and Web Access (I mean Web Access for TFS 2010; 2012 is better in this context). The most annoying thing is that I usually need to specify just title and estimate for tasks but have to wait until the whole complex task entry form is loaded and then closed. I also found bulk work items generation by means of Excel is not that convenient for addition of hierarchical (parent-child) data. So I made a small utility for this purpose. Details and source code are here:   https://github.com/marss19/bulk-task-generation-in-tfs How to use The main form is divided in 3 parts: main menu: you can select a TFS project here, specify an area and/or an iteration to filter displayed work items and select a template for tasks creation. The default template containing all required fields is created automatically for each p...

Two facts you may not know about storing ASP.Net Session in SQL DB

  If saving of large objects in the Session in InProc mode is bad practice then doing the same in SQLServer mode is real evil. The main problem in this case is serialization/deserialization data on every request to the server. Each user's session is a single record in ASPStateTempSessions table so all objects need to be deserialized even if you request something which is rather small. Symptoms of this problem: you notice using a profiler that usual int userId = Session["UserId"] takes a few seconds!!! to execute.     If you noticed that ASPStateTempSessions table is rather large and permanently grows and grows then check if the SQL Server agent is running. It is responsible for deleting of expired sessions. It should have a job to execute the DeleteExpiredSessions stored procedure every minute (by default).