Updating IP address in config - asp.net

Newbie question here, I am trying to change the IP address of our database server. In our config.cs we have:
public class Config
{
private const string DevelopmentIp = "127.0.0.1";
private const string ProductionIp = "199.199.199.199";
But on the live server we only have the compiled site. Is it possible to change the IP address without having to recompile the entire application? Is it possible to manually edit the live site with the new IP address?

You should never keep ConnectionString in your source code.
Instead, you want to keep ConnectionString in web.config. If you worry about hacking web.config , then you can decrypt it using aspnet_regiis.exe (which is not your original question).
But on the live server we only have the compiled site. Is it possible
to change the IP address without having to recompile the entire
application? Is it possible to manually edit the live site with the
new IP address?
Answer is No. You have hard-coded IP address inside config.cs. You need to update it, and re-compile the application.

Related

What can be done to avoid hosts file entry?

In our organization, we've a in house maven repository say http://mymavenrepo.com to store private artifacts and that is being used across projects.
But recently ip address of machine, where mymavenrepo was hosted, has changed and hence we had to make a change in hosts file with new ip to build maven projects successfully.
My question is why we need to make change in hosts file with changed ip and what can be done to avoid change in hosts file every time ip is changed, like for http://www.google.com, we never have to make entry in hosts file.
Well I would say this is somewhat of a loaded question. The Hosts file on your machine may overwrite a DNS query because it is the first file that a computer reads to find a domain. The Hosts file essentially acts as the DNS in the sense that it translates IPs to Domains.
Now, I am assuming that the local repository is a private repository or in other words NOT published on the internet. Which I might be wrong, but that would mean that it might have a private IP address accessible only to the local network which would make it reasonable to stay in the hosts file. If it DID have a public address, or accessible to the outside internet, then removing its entry from the hosts file would allow for the DNS to query it.
My suggested solution here based on my local-local assumption is to SET a static IP to the repository and exclude it from the DHCP server so it doesn't change. The way to do that depends on the solution you have and the underlying OS.

Access Multiple Web Sites Hosted on single server on local network from workstations

I am trying to set up a secondary web site hosted on our local domain controller running IIS-8.
I already have one site working successfully thought our network, the default site.
I have successfully got the second one to work on the localhost (the domain controller Server 2012-R2), but I can't seem to access it from any of the other workstations on our network.
I added the new site.
Set the binding to IP address:192.168.1.1, Port:80, Host Name:dyo.mysite.com
I have modifed C:\Windows\system32\drivers\etc\hosts to show 192.168.1.1 dyo.mysite.com, and I have added an alias to the forward lookup Zone in the DNS Manager. (Name:byo.mysite.com, FQND:byo.mysite.com.mydc.com, Target Host: 192.168.1.1)
I can't seem to access the site from any of the network work stations. I have tried many combinations of addresses, http://byo.mysite.com, 192.168.1.1/byo.mysite.com, \mydc\byo.mysite.com, etc.
I would imagine that I am probably missing something simple. I just don't know it is.
Any insight would be greatly appreciated.
To get your server accessed from other workstation. You have to promise
Your IIS site can be accessed via IP address directly.
the client workstation is using your DNS
Your client workstation is not bypassing your DNS server by .pac proxy
So could you get access the website via IP address by disabling default website and set the site to unassigned IP or 192.168.1.1 with null domain name?
If you want to access the website via byo.mysite.com. Then you shouldn't set FQDN like byo.mysite.com.mydc.com. because Web browser will never consider byo.mysite.com as an alias but a different server. That's why When you set FQDN like byo.myDC.com, you could get work by access http://dyo and you could also access website via byo.mysite.com.mydc.com but fail with byo.mysite.com.
How to set DNS correctly
To get it work, please create an new primary Forward Loopup Zone named mysite.com. Then create a new HOST(A) record to map to your machine name like dc.mysite.com and 192.168.1.1. Then create an Alias(CNAME) called www to map to this A NAME. Then the FQDN will be www.mysite.com.
Finally bind your IIS site and access the website should work.
PS: Please make sure your other workstation is not using a proxy.

NLog - Capture host's ip address

I am trying to capture the host / server's ipaddress within a .NET Core 2.0 application. The ${machinename} variable captures the server's name but how do you capture the server's IP address? The name is meaningless to my team but IP address is critical.
Lets say you have a static IP-address, then you can do this:
var localIpAddress = LookupIpAddress(); // See https://stackoverflow.com/a/50386894/193178
NLog.GlobalDiagnosticsContext.Set("LocalIpAddress", localIpAddress);
Then you can use it target layout like this:
layout="${longdate}|${level}|${logger}|${message}|${gdc=LocalIpAddress}"
If your IP-address sometimes are changing, then you can setup a background-thread/timer to refresh the NLog-GDC-value.
See also: https://github.com/NLog/NLog/wiki/Gdc-layout-renderer
NLog 4.6.8 has been released that include ${local-ip}:
https://github.com/NLog/NLog/wiki/Local-IP-Address-Layout-Renderer

IIS Adding URL instead of IP

I have a local only ASP.NET MVC app hosted in IIS, and I was wondering how I could use a URL instead of an IP? At the moment I access it using http://127.0.0.1, but I'd like something like http://foo instead
In IIS, you need to add a binding to the website, here you can specify the hostname i.e. foo.xyz.com
However, you will need to make sure that the DNS resolves that hostname to your IP address
You could add this line to your host file:
127.0.0.1 foo
You can find the host file here:
C:\Windows\System32\drivers\etc

IIS7 - Using an ip address and port number will not display a web site home page but using localhost will

Using ASP.Net I did a web site and can load it up in a browser window when pressing the F5 key in VS2010.
On the browser window I noticed VS2010 used an address like this to load the web site home page:
localhost:12345/
If I try to use the ip address for my computer found by using ipconfig to load up the home page,
1.2.3.4:12345
I get an error stating:
Could not connect to 1.2.3.4:12345
If I use:
1.2.3.4
I get the IIS7 default page.
The actual address and port numbers I used in this example are different than those I really used.
Can you tell me why localhost works but 1.2.3.4 does not work?
Can you tell me if I need to do something extra with IIS7 since I never did this before?
A couple of things to remeber. Your computer two types of IP address. The first is a private IP address and the second is a public IP adress. IPConfig will show you your local, private address. Your private address will not be accessible from anywhere outside your LAN.
If you would like to change your websites URL locally from localhost, you need to change your IDE's development settings.
This site has a great tutorial on how to do that.
First things first, the address Visual Studio gives you is a temporal address that corresponds to their development server (Webdev.Webhost or Cassini), this server doesn't allow you to connect outside your computer, that's why localhost:1234 opens your page, but 5.6.7.8:1234 doesn't.
Second, also you seem to have IIS configured, but what you need to do is deploy your site to IIS, here are Microsoft information about deploying your site: http://msdn.microsoft.com/en-us/library/20yh9f1b(v=vs.100).aspx, once deployed, you may create an Application on IIS or a Virtual Directory, for more information you can take a look here: http://technet.microsoft.com/en-us/library/cc772042(v=ws.10).aspx.
Once you have deployed and configured your application or virtual directory, you can access your site like this: localhost/MyVirtualDirectory (assuming you set a virtual directory).

Resources