Showing posts with label Visual Studio 2017. Show all posts
Showing posts with label Visual Studio 2017. Show all posts

Friday, February 15, 2019

Accessing web site running in Visual Studio 2017 using an alternative hostname

Assumptions:

  • Running in Visual Studio 2017
  • Running an application on port 8888
  • Url used to access the application is http://localhost:8888

If you want to access the web site using http://somenamehere:8888 you can do this by doing the following.

  1. Open your .vs/config/applicationhost.config file in a text editor
  2. Find the binding for your application.
    <binding protocol="http" bindingInformation="*:8888:localhost" />
  3. In the same <bindings> section, add another <binding>
    <binding protocol="http" bindingInformation="*:8888:" />
  4. Optional: If you are using https you will need to do the same. The key is that you match the ports.
You should be able to launch your web site in Visual Studio (Control-F5, etc). This will bring it up as it always have.

Now you need to hack your dns so that it can resolve your new made up hostname. In this example, it is somenamehere. The easiest way to do this is to open up your hosts file (C:\Windows\System32\drivers\etc\hosts) in a text editor and add the following line to the bottom of it.

127.0.0.1   somenamehere

You should now be able to ping that hostname and see that 127.0.0.1 is responding.

Now open up the browser and go to http://somenamehere:8888 and you should get your application again.

NOTE: If VS2017 gives you any issues, it may be helpful to run it as administrator.

Tuesday, November 20, 2018

Keeping Secrets out of the web.config

See here for Microsofts official recommendations on best practices to keep secrets out of the web config.

I am mostly concerned about appSettings and connectionStrings sections in the web.config

The Microsoft article says everything I am going to say below, but they are some important points to consider.

appSettings

To keep your appSettings secret, put them in another file that is not checked into source control. The contents of this file will be merged with what is in the web.config so this works well to allow developers to override values in appSettings.

The syntax is basically

<appSettings file="..\..\AppSettingsSecrets.config"> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings>

The file attribute accepts paths that are relative or absolve and the file does not have to exist. This is useful when deploying to different environments that may not use this file and instead use VSTS / replacing of tokens to manage values per environment.


connectionStrings

The connectionStrings section isn't as nice as the appSettings. The tags between connectionString tags are replaced by the contents of the external file. The file referenced MUST be in the same directory as the web.config that is referencing it. This means the secret file is per project. The other thing that makes it not work as easily is that it MUST exist otherwise you will get a build error because the project file will try to find the file. You can edit the project file and tell it to only include the file in the project for particular environments, but that is tedious and must be done on each project file.