Specify Name and Port for Website Project in IISExpress

When using IISExpress to develop a Website project it is nice to have a specific machine name and port to refer to.

You can specify the machine name and port by editing the binding in the IISExpress applicationhost.config file. The following information was gleaned from this answer on StackOverflow.

  1. Open your applicationhost.config file. It most probably will be %userprofile%\Documents\IISExpress\config\applicationhost.config, but inspect the output from iisexpress.exe to be sure.
  2. Locate your WebSite entry and add following binding with your machine name.
         <binding protocol="http" bindingInformation=":50333:your-machine-name" />
    
  3. Restart IIS Express

I actually specified my machine name as well as the local domain.

bindingInformation=":8013:my-machine-name.my-domain.local"

This seems to be working just fine for me. If you are wanting to actually share that url for others to access (maybe within your own work network) you might have to run this in a administrator command prompt as specified in this StackOverflow answer:

netsh http add urlacl url=http://vaidesg:8080/ user=everyone

 

The Case of the Disappearing Cookie

If you are working on a site that doesn’t have a proper TLD (i.e. http://localhost:8013) you will notice that setting cookies on the browser doesn’t seem to work the way it should. Sometimes your cookie, which works perfectly fine on a site with a TLD, will not show up on your local site.

For example, this code will work perfectly fine on a site with a TLD but not on your local site.

newCookie = New HttpCookie(ConfigurationManager.AppSettings("YOUR_SPECIAL_COOKIE_NAME"))
newCookie.Domain = ConfigurationManager.AppSettings("BASE_DOMAIN")
HttpContext.Current.Response.Cookies.Add(newCookie)

At this point you might be thinking, ‘I did everything right, where did my cookie go?‘.

This comes down to how the browser handles setting cookies that have a specified domain. The browser prepends a ‘.’ (that’s a dot) to the beginning of any domain specified for a cookie. On normal domains this basically just says that this cookie is valid for this domain and any subdomains. The following non-doctored image proves it:

Set two cookies, one with a specified domain and one without.

Setting Test Cookies
JavaScript to set test cookies for the superfrogadventures.com domain.

This results in the following two cookies

Shows the results of the first cookie set.
Shows the results of the first cookie set.
The Second Test Cookie
Shows that the domain does not have a dot.

You will notice that the domains are a bit different. One has a ‘.’ while the other does not.

So. All this to say, if you are developing locally (or on a site without a TLD) then you will need to save your cookies without a “domain”. This will ensure that the cookie is accessible. Otherwise you will probably need to create yourself some sort of domain with a TLD.