Categories
Programming

Prevent AJAX Requests Making Sessions Infinite in ASP.NET MVC

If you are terminating inactive sessions in your ASP.NET MVC application and you add an AJAX polling call, the chances are you’ll make your sessions last forever thanks to the AJAX request bringing down an updated session cookie. This is because the AJAX call will pull down an updated auth cookie and extend your timeout. […]

Categories
Programming

Html.RenderAction Equivalent in .NET Core MVC

If you were a fan of ASP.NET MVC Widgets using Html.RenderAction, you might be a bit stunned that RenderAction is nowhere to be found in .NET Core. Don’t worry, though, because there is a Html.RenderAction equivalent in .NET Core MVC and it’s called View Components. View Component Class The view component class is quite a […]

Categories
Programming

Minification Failed. Returning Unminified Contents.

Has you ASP.NET applicaiton reported that minification failed? If you are using bundles in application, you might come across this exception comment at the top of your larger-than-expected bundle file. /* Minification failed. Returning unminified contents. (List of problems here) */ It can happen for JavaScript or CSS, but it means minifier has found something […]

Categories
Programming

ASP.NET MVC Widgets with RenderAction

This is a useful pattern that I have successfully employed a couple of times with ASP.NET MVC applications; creating Widgets with RenderAction. The prevalent way to create a page in ASP.NET MVC is to grab a bunch of stuff in the controller and pass it into a view to be rendered. As the application grows, […]

Categories
Programming

Squash ASP.NET MVC ModelState Errors into a String or JSON

Once ASP.NET MVC has done all of the hard work of validating a model for you, you may find yourself wanting to squash the ModelState values into a string or JSON object. Because of the hierarchy, it might not be obvious at first glance how to do this, so your best bet would be to […]

Categories
Programming

ASP.NET MVC Image Squishing with Picz

Responsive images have been around for a while and have wide browser support as well as a strong fallback story for older browsers. The one thing holding us back from using them is the manual workflow… Arrive at office Create images at different sizes Upload images Write an HTML tag listing all the image sizes […]

Categories
Visual Studio

How To Fix Broken Intellisense in Visual Studio Razor Views

I had an annoying issue in Visual Studio 2015 whereby the views lost all intellisense. Errors such as “The name model does not exist” and lack of assitance with HTML Helper methods were accompanied by red squiggly lines. Most of the advice for fixing this is based on the assumption that the views are broken […]

Categories
Programming

Handle Legacy .aspx Page Requests In ASP.NET MVC

If you have a public web application that you are upgrading from Web Forms to ASP.NET MVC, you may find yourself wanting to capture requests to the now obsolete .aspx addresses. By default, these requests won’t be passed to your application so you won’t be able to catch them using a route. So to get […]

Categories
Programming

Translating Your ASP.NET MVC Routes

There are a ton of ways to localize your ASP.NET MVC application when it comes to the text your display on the page. When it comes to the URLs, though, it is not uncommon to see a site in one language with routes in another. It seems a real shame to see a website in […]

Categories
Programming

Request and Response Class Splitting

This is something I don’t seen done a lot in real life, so I thought I’d write briefly about it. This topic gets a lot of talk, but not much action and in reality I think schedule pressures are the most likely reason for this refactoring (and most others) never actually get considered. I’m talking […]