*.dannyg

Reinstalling WCF on Windows

Mar
24

PartialView: Why?

Mar
22

There are several cases where you would want to break down your view into several small components. One use case that I am working with right now, is I have a multi-lingual site that I would like to reload content using AJAX principles.

Normally what I would do in the case of a non-multi lingual site is to create another ActionResult to return the ViewModel that is changing with the new parameters. I like to use a custom ActionResult that I have called JsonpResult. The problem resides in the fact that I have labels not in my database but in Resource files. So what I would need to do is to somehow hydrate my Resource file data into the ViewModel.

Once the data comes down the pipe, my AJAX callback handles the wiring up of the ViewModel response back to the HTML page using Javascript (I use jQuery).

This definitely works, however it becomes a question of maintainability. I now need to not only maintain my original ASP.NET view, but I also need to maintain a set of scripts that handle AJAXian behavior. If you need to have your site SEO, then you really need to make sure that both the Server Side and Client Side behavior are both working the same.

This is where Partial Views come into play for me. What I do is "pull out" the logical data sections where the bulk of the reload occurs. The nice thing about PartialView is that you can pass your ViewData and Model along to the PartialView. If your PartialView is strongly typed against your ViewModel you can get Intellisense to help with the wiring of the PartialView.

Now all I need to do with my AJAX call is to write the response back to a single DIV rather than handling data points individually. What it does mean is that there would be more content coming down the pipe. However, the trade off is easier to read and maintain code.

Technorati Tags: ,,,

Reverse Proxying With IIS7

Mar
09

There are some really nice modules to add on to IIS7.  One of the them URL Rewrite.  You can also set up a Reverse Proxying rule.  This basically allows you to re-route any traffic that might be specified in DNS to a different server.  In this particular scenario, the DNS rules couldn’t be changed because they weren’t owned.  However, because there is control over the destination server, I can re-route incoming traffic to a different server.

image

Double-click on URL Rewrite on the website that is accepting the incoming traffic.  Then “Add Rule”.  Select “Reverse Proxy” rule.

image

Now you can specify the new destination for all request.  You can be a little more specific about links with regular expressions if necessary.

image

Now you can test your theory by opening your web browser and pointing to the original domain name.  You can even rewrite links in the response.

Technorati Tags: ,,

Powershell Script: Convert RGB to HEX

Mar
01

Sometimes when I’m doing web programming (namely CSS), I need to quickly convert RGB to HEX.  So, I have written a neat little Powershell script.  Keep in mind that you might have to enable the ability to run Powershell scripts on your system (if you haven’t already, there are plenty of sites out there that show how to do this).  You should save this script as RGB2HEX.ps1

 

foreach ($arg in $args)
{
    $hexval = $hexval + [Convert]::ToString($arg, 16).ToUpper() 
}
 
Write-Host "Hex value :: $hexval"

To run this on the Powershell Console, do the following (in this case I’m testing converting 255 255 255 to hex)

.RGB2HEX.ps1 255 255 255

image