ASP.NET cannot resolve user hostname in azure - asp.net

I have written an ASP.net website that gets the machine name from the person browsing the website using
sName = System.Net.Dns.GetHostEntry(Request.UserHostAddress).HostName.ToString
If I publish this to a web server on our local network, it works fine.
We also have an Azure server and I want to publish it to that server, but it does not return the machine name. We have the Azure server connected to our local network via a permanent tunnel.
I'm assuming that the code can't resolve the name as it can access the DNS on the network. Is there a way around this?
Thanks
Gareth

AFAIK, Our app will not work with Azure DNS Private Zones automatically. To work with Azure DNS Private Zones we need to add the below in app settings:
WEBSITE_DNS_SERVER with value 168.63.129.16
WEBSITE_VNET_ROUTE_ALL with value 1
For more information please refer this MS Q&A as suggested by # didier3001
And this for use Dns.GetHostEntry Method

Related

Configure 2 sites in the IIS of windows Server 2016

I have to configure a staging site of my web application in Windows Server 2016.
I have ASP.net site which is running smoothly in my win server 2016, and I have configured A record from my bluehost DNS Manager.
My Question: I want to add a new site in the IIS of my server using same port. So how I could manage to reach it from A record or CNAME record from bluehost?
As far as I know, IIS doesn’t allow two websites to use the same port number when we using the same alias for the local machine.
To create a unique binding, we need to specify another name(HostName) for the second website. Edit the binding and specify the unique hostname the user will address to.
Now, we can start the second website as well.
All we have to do is to add an alias for the server(A or CNAME) to DNS that specifies the IP address or the name of your web server.
Here is a related discussion.
http://woshub.com/run-multiple-websites-on-the-same-port-and-ip-address-on-iis/
Feel free to let me know if there is anything I can help with.

Get Client Host name on Azure ASP App

Trying to get the local machine name for an Azure hosted ASP application.
Request.ServerVariables["HOST_NAME"]
returns 127.0.0.1 as does HOST_ADDRESS
In fact I can't find anything in Request.Server variables that reflects the local hostname.
Dns.GetHostEntry(Request.UserHostAddress).HostName
will not work as this is a server side lookup, so all you get is the public gateway name not the actual end-user machine name.
Any ideas?
I am stumped and just feel this should be so simple!??!
As you're potentially behind a load balancer when you deploy to azure try using
Request.ServerVariables["REMOTE_ADDR"]

How to publish an asp.net website on work network?

I have been developing an ASP.NET application and I would like my work colleagues to give me feedback on it. I tried running it on IIS but because the database is located on a remote server, I am unable to host it properly?
Also, how can the colleagues access that site? my host name, etc
You can update your connection string to your remote server (providing the DB accepts external requests).
Something like (assuming SQL)
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase; User ID=myUsername;Password=myPassword;
It's an ugly hack, but you can do an if else statement, detect the DomainName (Environment.UserDomainName()) and if matches the server then use one connection string, if it's your office's domain, then use that!
This means, you can still use your local IIS!
You can publish your web site on a local server which has IIS running on it. You can create your application on IIS and your colleagues can access your web site from the intranet via the name of the server easily.
Such as:
http://servername/yourprojectdirectory
And also the local server should have internet access for the remote database.

azure connect between azure myWebRole and nonazure server not working

My webapplication hosted on windows azure, needs to communicate with TFS Server. When any one login to my web app using live id, I want the logged in user to use my Team foundation server(TFS) credentials -username,password and domain to programatically authenticate and connect to our TFS server and create some work items.
I configured my azure connect for the communication to happen between azure WebRole and TFS server (our TFS is non-azure ).I added both the WebRole and the TFS Server into single Connection Group
In my azureportal ,I can see mywebrole and my TFSServer as connected the machine endpoint is active, and that it refreshes since the last connected updates
.But when I try to run my web application from azure and when it tries to communicate with our TFS server ,its throwing error message saying Error message : Team Foundation services are not available from server eg.,http://xyz-abcxyx-01:8080/tfs/eas/. Technical information (for administrator): The remote name could not be resolved: 'xyz-abcxyx-01'
Any suggestions to resolve this issue ?
You should enable remote desktop on your WebRole and connect to one of your instances. Then, try to ping the IP of your TFS server (not the hostname xyz-abcxyx-01). Maybe this is simply a DNS issue (even though using hostnames works with Windows Azure Connect).
If pinging the IP works, but pinging the hostname doesn't work you have a few options left:
Use the IP instead of the hostname. This won't work if you configured your TFS to use host headers.
Create an elevated startup task to modify the hosts file and map the IP to the hostname. In your code you can keep working with the hostname.
Try to modify the DNS server configured in your WebRole to use the default DNS server + your internal DNS server. But to me this doesn't look like a clean solution.
Anyways, in each solution you'll want to store the IP/hostname in the ServiceConfiguration and make sure your code supports changes to the ServiceConfiguration. This will allow you to change the IP/hostname without having to redeploy.
You should check if TFS server is listening on all network interfaces, include the one created by Azure Connect (start with 2a01). Next try to connect to TFS from a machine on the local LAN, just to make sure it is configured correctly. You don't need to use IP for referring to TFS, DNS name is definitely supported out of box.

IP permission problem in Web Service Publish

I have a weird case here at work.
The customer(telecommunication firm) has a server which we publish asp.net web service codes which we designed for them. We use that server and web service to get data from the customers own web service and give out for client(telephone) to use it.
The customer does not allow us to code on the remote server, so we have to work on local computer.
The customer has 2 IPs for its own web services. One of them can be reached only from the remote server, this is an internal IP. Second IP is public which I can reach from my local computer. They address the same methods. For security reasons, they divided IPs.
Everything is fine while developing on local. But when I need to publish web service to the server, I need to change web service URLs to remote servers internal IP. But the local Visual Studio web reference doesn't change web service URLs because it can't reach to service as it is only permitted to reach from the server. So I cannot get a build and publish my code.
Somehow I need to change my visual studio reference URLs to internal IP(so far nobody can reach from local), in order
Hope I am clear.
Thanks
It can be changed from the web.config of your local project.

Resources