Landscaping website for a friend

These past few months I have been cultivating my web development skills in order to create a funky web site for a friend’s landscaping business.

The website can be found here: Greenspade Landscaping

website.jpg

My goals were to increase my knowledge around modern web development technologies and gain further experience working directly with a business stakeholders.

Key features and technologies used:

  • Responsive design & Liquid layout using Bootstrap framework
  • Unobtrusive Ajax to load partial views within parent
  • MVC 4.5 with Razor
  • Spam bot protection using a checkbox captcha and “honeypot” control

One of the great things about working on this project was that I also got to delve into the creative side of things and explore the domain of web site design

 

 

Disabling Selected Code Blocks Using Conditional Compile Directives

This post outlines one way to safely disable specific code blocks through the use of conditional compilation statements which can be useful for the purposes of debugging. The approach taken in this article also aims to eliminate the risk of any such code getting accidentally disabled in a production environment.

A common scenario where you might want to disable or skip some code during debugging is in the case of an Authorization method which checks the credentials of a calling client. Consider the AuthorizeClient method pseudo code below


private void AuthorizeClient()
{

if(!ClientAuthorised(userIdentity)
{
throw new AuthorisationException(UnauthorizedUserMessage);
}

}


By putting the code inside a conditional DEBUG compile region, you can ensure that this check will only be skipped if the code is compiled in debug mode.


private void AuthorizeClient()
{

#if DEBUG
return;
#endif

if(!ClientAuthorised(userIdentity)
{
throw new AuthorisationException(UnauthorizedUserMessage);
}

}


However, sometimes it might be useful to perform the validation check in debug mode. For example, you might want to ensure that the validation is still working properly after making some changes.

In this case, you can add a configuration element to the application’s app.config file which can then be set to the value desired. Through the use of xml pre-processing we can also ensure that this key\value pair is populated only in a development environment thereby preventing the configuration file from getting littered with unused settings

1.) Put a key\value into the app.config file. This setting will only be present when the application is compiled in a developer environment as per your environmental settings


<!–#ifdef ${DEV_Environment}–>

<add key=“DisableAuthorityCheck” value=“true”/>

<!–#endif–>


2.) Modify the AuthorizeClient method to additionally check for the value of the DisableAuthorityCheck setting if it is present in the config file


private void AuthorizeClient()
{

#if DEBUG

if(ConfigurationManager.AppSettings.AllKeys.Contains("DisableAuthorityCheck")&& ConfigurationManager.AppSettings.Get("DisableAuthorityCheck") == "true")

return;

#endif

if(!ClientAuthorised(userIdentity)
{
throw new AuthorisationException(UnauthorizedUserMessage);
}

}


The approach outlined above is however not without it’s drawbacks. For example, overuse will result in code being littered with conditional compile blocks which may bloat the code and make it less readable.

Simulating Network Latency using Fiddler

This article demonstrates how to use SoapUI together with Fiddler to simulate network latency. Such a simulation can be useful to validate application behaviour under poor network conditions or slow 3rd party responses. A performance monitoring tool (such as Windows Performance Monitor) can then be used analyse system resource consumption

The following tool versions were used: SoapUI 5.0.0, Fiddler 4.4.9.7

Setting up Fiddler

1. Select Customize Rules… from Rules menu in Fiddler toolbar

fiddler

2. Add code for custom rules to CustomRules.js. (I suggest saving a copy of this file before hand)

i)  Declare new rules option to introduce the delay

customJs_1

ii) Define the action to take when m_ThirdParty5sDelay is true. In this case, if the uri contains “thirdParty” then both the outbound request and inbound response will be delayed by 5 seconds (10  in total)

Note: Delaying only specific requests is useful if you want to simulate a delay for specific 3rd parties without affecting other application calls. However if you just want to simulate general slow network conditions, simply omit the and clause with the oSession.uriContains(“ThirdParty”)

customJs_2

3. After saving the file, a new option for “Simulate third party 5 second delay” appears under the Performance menu.

Setting up the client:

If you are interested in measuring the performance of a service, you’ll want to introduce delays between the service and a 3rd party (or whatever else you may be calling across a network). In this case, configure the service’s proxy settings to go via Fiddler (which runs on 127.0.0.1:8888 by default)

If SOAPUI will be used (e.g. in place of a client application making calls to a service) then it needs to be configured to send requests through Fiddler. This can be done by changing the SOAP UI proxy settings to use the fiddler default proxy:

soapUiProxySettings

What this blog will be about

The 3 main aims of this blog are:

  1. To make a meaningful contribution to the developer community
  2. To provide a helpful online technical reference for others trying to learn or implement similar technologies
  3. To act as a source of motivation for my own learning and professional development

I hope to achieve these by doing the following:

  1. Providing technical details of how I overcame problems and challenges where online resources were scarce or unavailable
  2. Providing summary notes on key concepts and highlighting any cautionary tales or “gotchas” that I encountered.
  3. Sharing any useful techniques or tools that I come across as well as occasionally chiming in on the latest developments in .NET or related technologies