Friday, September 25, 2015

Use custom domain instead of localhost

when you run your asp.net mvc application on IIS Express sometimes you might need to change address in to some custom domain(www.example.com) instead of localhost(http://localhost:[port]). In this post i'll explain how to do that. firstly we just change a couple of things.first go to project properties and change values as follow.

then you need to change IISExpress configuration file called applicationhost.config  located at %USERPROFILE%\Documents\IISExpress\config and update relevant site settings like this.

Important: Make a backup of your config file. You can really screw things here.


<site name="Purl" id="1"> 
    <application path="/" applicationPool="Clr4IntegratedAppPool"> 
        <virtualDirectory path="/" physicalPath="D:\Purl\PurlApplication" />                     </application> 
    <bindings>
        <binding protocol="http" bindingInformation="*:80:" /> 
        <binding protocol="https" bindingInformation="*:44300:localhost" /> 
    </bindings> 
</site> 
and to update host file with relevant example domain open notepad in administrator mode and go to to %SYSTEMROOT%\System32\drivers\etc  open host file
add update like this
 
Go back to your project and hit Ctrl+F5 to start IIS Express again. some cases site won't run and Visual Studio won't update settings in to localhost in that case start visual studio in administrator mode (run as administrator).

and you are done!!!