Tuesday, 30 March 2010

Internet Explorer Profiling Tool

John Resig (Creator of jQuery) posted a link recently to an excellent client side tracing / profiling tool for Internet Explorer - DynaTrace. Check it out:

http://ejohn.org/blog/deep-tracing-of-internet-explorer/

Friday, 19 March 2010

Linux disk free space

All system admins will need to check, at some point, how much disk space is free on their systems. If the system is remote, or perhaps in a datacenter, you will need to run a shell command. the one you want is:

> du

This basic command outputs the space in terms of 1 kilobyte chunks, which isn't very readable. to get a nicely formatted output, run this:

> du -h

Nice and easy huh? Now why not script it and put it into a cron job??

Localhost not working in fiddler - a solution

I was testing my .net site in Internet Explorer today using Fiddler. The Visual Studio development server uses localhost with a random port. However, Fiddler will not captures responses from localhost.

Don't worry, though. There's a neat trick you can do to fix this localhost error. Let's use an example. If you are testing the page:

http://localhost:2622/MySite/Default.aspx

simply change it to:

http://somesite.com:2622/MySite/Default.aspx

The url http://www.somesite.com points to localhost. 

This is a really neat trick for working around the fiddler localhost restriction.

The proof:
Hooray!

Monday, 15 March 2010

Consuming ASP.NET AJAX Web Services in jQuery

Nice clear information.

This can also be used for Page Methods, if you prefer to avoid sending the SOAP header. However, you will need to Serialize the response as JSON.

Link below:

http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

Saturday, 13 March 2010

IIS7 rewrite rule for requests from the local network

First, if you don't know about the IIS7 rewrite module, read my earlier post on it.

You back? Good.

So today I was trying to debug my web app. My web server's internal ip is 192.168.1.80, but whenever I typed this into my browser, it would send me to http://www.192.168.1.80

I discovered that this was because of one of the rules I setup earlier in the IIS7 rewrite module:

<rule name="Non www to www redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.yoursite\.com$" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>

Can you see why? An IP address clearly doesn't match the pattern. To solve this problem, I just added a second condition to the rule:

<rule name="Non www to www redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.yoursite\.com$" ignoreCase="true" negate="true" />
<add input="{HTTP_HOST}" pattern="^192\.168\.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>

So what is this doing? Well, it's simply saying: "If the url contains the full site name, or the request comes from inside my network, ignore this rule". Or rather, it's APPLYING the rule to anything that DOESN'T match the conditions (that's what the "negate" attribute means).

That's why I love the IIS rewrite module. I love the way you can stack conditions like this. It's nice and understandable, and easy enough to change to do whatever you want.

Friday, 12 March 2010

Granting permissions to another computer in Windows

Hello there!

Do you ever get confused about which user to grant permission to on a specific folder?

What if you want to simply want to grant any access requests from another computer? (perhaps the other computer is a front end server - in web hosting, it's common practice to store your static files on another server).

One other reason to do this is so that you don't have to set up asp.net impersonation to give your asp.net website access to a network resource (the most common way of doing asp.net impersonation is storing cleartext passwords in web.config, which is kinda frowned upon).

Well, all you need to do to work around all the above issues is give the other computer itself permissions, then any user on the other computer will inherit the permissions (like the network service/aspnet user, for example):

  1. Open up the permissions/properties dialog for the folder (XP/2003 dialog shown below - in Vista/2008 you would right click and go to Sharing/Permissions).
  2. Click Add.
  3. By Default, the only "objects" you can share with are Users, Groups and Security Principals.
  4. Click on the "Object Types" button and check "Computers".
  5. Under "Enter the object names to select", type the other computer's name followed by a dollar ($) sign. For example "WEB$".
  6. Click "Check Names".
  7. Once the name is verified, click OK. You will now see something like this:


Now just set up your permission - this depends on what you want the other computer's users to be able to do (in my case any user on the WEB server). At the most, you should only need to give read and write access. Higher permissions like List Folder Contents, Modify and Full Control should only be granted to the Administrators group.

By the way, if you're running IIS7 remember to set the Application Pool to use the NETWORK SERVICE user, not the default IUSR, or this won't work. I'll detail how and why in a future post.