↓ Skip to main content

Articles

Active links on Bootstrap Navbar with ASP.NET MVC

·2 mins
If you have used Bootstrap with your ASP.NET MVC application, you might have faced some issues with implementing active links of it’s Navbar component. We’ll have to dynamically add a css class called active to the particular menu item in order to make it selected in the Navbar. Here is a HtmlHelper extension which is capable of rendering menu items as well as drop-down menu items. I’ve used ASP.NET MVC 5 with Razor and Bootstrap 3.

How to Rank your search results with multiple search terms using LINQ and EntityFramework

·2 mins
I have always used a ranked search criteria, it’s the only true way to get good results back from a data set. But I’ve been doing my ranking within C# code. But this got all the data from the data source and then ranked the results. This is very poor on performance, as we should only be returning back the results for the page size we require.

Backup SQL Azure

·7 mins
There are a number of options for backing up SQL Azure, which can be found here: Different ways to Backup your Windows Azure SQL Database I like the Azure way, which is just exporting, importing and setting a scheduled

Vertical And Horizontal Privilege Escalation

·2 mins
What is Vertical And Horizontal Privilege Escalation? Does your application support for this internally authorisation verification of work? I expect not, it is really an over sight of the architecture and application planning that this is missed out and more importantly when it becomes an issue it is more often than not too late to implement any changes.

Make Fake MVC Objects for testing

·3 mins
If you need to create some Fake MVC objects for testing MVC objects then here you are: FakeControllerContext using System.Collections.Specialized; using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Web.SessionState; using MvcContrib.TestHelper.Fakes; public class FakeControllerContext : ControllerContext { public FakeControllerContext(IController controller) : this(controller, null, null, null, null, null, null) { } public FakeControllerContext(IController controller, HttpCookieCollection cookies) : this(controller, null, null, null, null, cookies, null) { } public FakeControllerContext(IController controller, SessionStateItemCollection sessionItems) : this(controller, null, null, null, null, null, sessionItems) { } public FakeControllerContext(IController controller, NameValueCollection formParams) : this(controller, null, null, formParams, null, null, null) { } public FakeControllerContext(IController controller, NameValueCollection formParams, NameValueCollection queryStringParams) : this(controller, null, null, formParams, queryStringParams, null, null) { } public FakeControllerContext(IController controller, string userName) : this(controller, userName, null, null, null, null, null) { } public FakeControllerContext(IController controller, string userName, string[] roles) : this(controller, userName, roles, null, null, null, null) { } public FakeControllerContext ( IController controller, string userName, string[] roles, NameValueCollection formParams, NameValueCollection queryStringParams, HttpCookieCollection cookies, SessionStateItemCollection sessionItems ) : base(new FakeHttpContext(new FakePrincipal(new FakeIdentity(userName), roles), formParams, queryStringParams, cookies, sessionItems), new RouteData(), (Controller)controller) { } }

Disclaimer Page using MVC

·2 mins
If you ever need a disclaimer page in MVC, there are a few things you need to consider, the first is you should not be able to get to a page without agreeing to the disclaimer and if you have to re-login then you need to be presented with the disclaimer page again.

What is the difference between running in Debug and Release mode?

·4 mins
Is the only difference between Debug and Release configurations that Debug have the DEBUG constant defined, and Release produces the Optimize code? Are there performance differences between these two configurations. Are there any specific type of code that will cause big differences in performance here, or is it actually not that important? Are there any type of code that will run fine under the Debug configuration that might fail under Release configuration, or can you be certain that code that is tested and working fine under the Debug configuration will also work fine under Release configuration. The C# compiler itself doesn’t alter the emitted IL a great deal in the Release build. Notable is that it no longer emits the NOP opcodes that allow you to set a breakpoint on a curly brace. The big one is the optimizer that’s built into the JIT compiler. It does make the following optimizations:

Unit Testing a Private Method

·1 min
With Visual Studio keep changing the way you create unit tests I thought I’d document down how to test a private method the easy way. Here is a simple HomeController and we want to test that the GetPageSize method return 20 in a unit test.

Automation Testing

·1 min
Automation Fesability.docx (259.00 kb) Automation tools and estimation.docx (16.94 kb) EXCEL- SHEET for estimation.xlsx (21.06 kb)

Concurrency

·1 min
Hisenbugs Hard to test concurrency, useally have test over a 5 week period and when you find the issues it is hard to reproduce Lots of threads, and the behaviour of the program changes state and the interleaving changes and therefore it becomes hard to reproduce the concurrency issue, this is hope based testing, running on n number of machines and hope that we find a concurrency bug. This is not only costly, in having the ability to run all the processes on multiple machines, the resource involved in managing the logistics for running all the tests and more importantly if you find a concurrency issue can you reproduce the bug.

Migration from SQL to SQL Azure

·1 min
Tasks in Migration Migrate users and login ID’s Map data types Map database objects: tables, triggers, views, stored procedures Update incompatible objects to work with SQL Azure Update application to work with SQL Azure Migrate data to SQL Azure

Visual Studio 2013 requires Internet Explorer 10 – how to install without IE10

·1 min
Not my fix, but it works @ECHO OFF :IE10HACK REG ADD “HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer” /v Version /t REG_SZ /d “9.10.9200.16384” /f REG ADD “HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer” /v svcVersion /t REG_SZ /d “10.0.9200.16384” /f REG ADD “HKLM\SOFTWARE\Microsoft\Internet Explorer” /v Version /t REG_SZ /d “9.10.9200.16384” /f REG ADD “HKLM\SOFTWARE\Microsoft\Internet Explorer” /v svcVersion /t REG_SZ /d “10.0.9200.16384” /f GOTO EXIT :REVERTIE REG DELETE “HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer” /v svcVersion REG DELETE “HKLM\SOFTWARE\Microsoft\Internet Explorer” /v svcVersion REG ADD “HKLM\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer” /v Version /t REG_SZ /d “8.0.7601.17514” /f REG ADD “HKLM\SOFTWARE\Microsoft\Internet Explorer” /v Version /t REG_SZ /d “8.0.7601.17514” /f GOTO EXIT :EXIT

URL Activity Tampering and how to prevent it in MVC

·13 mins
No web applications are developed without concerning the security issues. But it is not sure whether the security measures are implemented correctly and the applications are well protected. We could see a lot of web applications query string parameters in plain string which are easy to manipulate and way to escalate restricted resources. Even the URL parameters are encrypted there is still a chance of a bruteforce attack by manipulating the encrypted hash and it yields when the database is large where the chance of matching a random hash is high. So it is clear the importance to protect the URL in the web application is necessary for all programming platforms. Here, this is discussed with reference to ASP.NET MVC and the utility class is presented.

Clean Content to help searching

·3 mins
One of the issue we all faced with is when a user searches for content, we are allowing the end user to be able to search for anything and this could result in unnecessary searching or cause the backend to perform searches which could result in DOS attacks via SQL.

URL Validator

·1 min
I needed to check to see if a URL that the user was entering was a valid Url, does it contain HTTP:// or HTTPS:// I ended up writing a small ValidationAttribute to add to the collection I am now building up, here is the code:

Using the WebGrid in MVC correctly

·6 mins
I know the WebGrid is a basic Grid control, but sometimes you are constrained with what you can use with a customer and WebGrid is by default from Microsoft so it is safe to use and does not require any unknown third party tools to be installed.

Catching Exceptions with Elmah within WCF

·2 mins
We all use the excellent ELMAH to deal with unhandled exceptions in an ASP.NET 3.5 web or MVC application. This works extremely well for all of the site, now what about WCF how can we get Elmah to work for us?