Current.Request.Url give my computer IP address not domain name - c#

I don't know about networking, but I ask my sysadmin to host my application into subdomain at our official site, for example the official site of my office is downtoearth.com. And then he just ask IP address of my computer where I developed my application, then he said that my application already accessible from myapp.downtoearth.com
I can open my application from that domain, but my problem now is when I try to get my current URL, it give me IP address of my computer. I tried using HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) and HttpContext.Current.Request.Url.Host but it give me the same result, what I want is my domain myapp.downtoearth.com/ not my IP address. Is there some ways to solve it?
My internet office use Proxy, so my computer didn't have an IP public. Of course if it give IP address of my computer, it will get error 404 not found. I use Razor MVC4 and IIS 8.
Sorry if there is some misspelling, English is not my default language and this is my first question at stackoverflow. I hope you understand my problem.

Probably your application is behind some load balancer. You shouldn't use the Request.Url as this is not working as it is expected in all circumstances. In your case the request is treated as local and this is why Url is your IP. Instead you can use Request.UserHostName. Please find this link

Related

C# get iPad/iPhone MAC/Wifi address

I am trying to find a solution to get the client's iPad unique MAC/Wifi address. I found some solutions here but it gets the MAC address of the server, but I want the client's address.
Thanks.
It is not possible to retrieve the clients MAC address, the MAC address is determined by the clients hardware and due to many restrictions your web application tipically canĀ“t get it.
I tried various workarrounds using javascript a long time ago without any success.
Here is a more detailed discussion about the same topic:
how to get mac address of client that browse web site by asp.net mvc c#

How to get client's computer MAC Address and IP in asp.net?

I want to get client computer MAC address and IP at the time of login for purpose of uniquely identify the client computer.
To get the user's IP address you can use Request.UserHostAddress or Request.ServerVariables["REMOTE_ADDR"].
Getting the MAC address I am not sure it is so simple. It is not something that is available to the server (ASP.NET) like the IP address is. From what I know you will need to use client scripting and ActiveX or Java applets to get to that information (after multiple installation and security prompts on the users' machines).
So in other words, get IP address by Request.UserHostAddress. Avoid using MAC address and look for another solution if IP is not unique enough for your needs. Maybe combine it with browser User Agent string instead (Request.ServerVariables["HTTP_USER_AGENT"] or Request.UserAgent but the latter might not be available in older versions of .NET).
You can get client IP address from request objects UserHostAddress property like
Page.Request.UserHostAddress
Looks like there is no straight forward way of getting client MAC address except using WMI which other answers already have pointed on.
refer to the below link , may be they will be useful for you...
http://forums.asp.net/t/1911211.aspx?Get+Client+Mac+Address+in+Asp+Net+Web+Application
http://www.codeproject.com/Answers/187064/i-need-MAC-Address-of-client-machine-using-asp-net#answer1

connect localhost from another machine

Is there anyway i can navigate to a website i develop on my computer from a smartphone connected to the same network?
the site is running on localhost, can I make a bridge or something like that?
thanks.
I think you can if you use you're IP directly as the website's name.For example in TOMCAT all the sites are localhost:port/Project_name/filename.html
So if you would use "http://your_ip:port/Project_name/filename.html", it should work.
As a note, the firewall may stop this from working.
As long as your site is available to the network, just use the name of your PC.
So if you were developing on http://localhost:12345 connect using http://muzE-PC:12345 (assuming muzE-PC was the name of your computer)
instead of localhost use, ip address.
Make sure that website is not blocked by windows firewall.
ipconfig can be used to determine ip address.
On remote system, localhost will refer to that remote system (not the system on which web site is running).

Is it possible to write C# code as below and send email using network in different country?

Is it possible to write C# code as below and send email using mnetwork in different country?
MSExchangeWebServiceURL = mail.something.com/ews/exchange.asmx
It's a web service URL. This works great when I run the same code from home network, my friends home network anywhere around, but when I run it from my client's location in Columbia it fails.
I have a valid user name and password on that Exchange Server. Is there any configuration that I can set to achieve this?
BTW this code below works when I run it within office network and any network within any home network. I have tried it at least with five friends network in Plano, Texas. I want this code to work running from any network in another country.
My client in Columbia can connect to the web service using a browser using the same user name and password, but when I run the code above it is not able to connect to our web service.
EDIT: Based on the comments and updated post, I would wager that the client location has a proxy server or firewall that is blocking the traffic. The client probably needs to add the relevant domain to whatever "whitelist" they have.
If it works from an internal network, then the problem is most likely not the code. You need to debug it and see what error turns up when running it outside of the network. Then check the logs on the firewall and the target exchange server to see what is happening.
One possible culprit is that the DNS name is not setup outside the office network, or that the office firewall is not setup to pass traffic (or only to pass SMTP traffic) from the internet to the server in question. Another is that Exchange Web Services is not setup properly to accept requests from the outside world. That can be tested from http://www.testexchangeconnectivity.com/.
If this isn't enough for you to get there, post more info about what errors you are seeing. "It isn't working, I want it to work" kind of reminds me of the Star Trek TNG episode about the species who kept telling Geordi to "make it go".
If you are asking if the code works (which it doesn't look like you are but it's in your post) you should ask on stackoverflow. If you are wondering why it won't work from home Its likely because the edge server is not set up to relay, and if you are at home and not vpn'd into the network that's all you have access to.
You need to break this down a bit:
What's the MSExchangeWebServiceURL? I don't need to know your real URL, but is this resolvable from your home network? i.e. is it an internal DNS host (server.mycompany.local) or is it an externally-resolvable DNS host (mail.yourcompany.com)?
If it's internal, like another poster said, you'll at least need to VPN in (or replace that with the external URL).
I'm not a big C# guy, but I'm guessing it's looking for your Exchange Server hostname or FQDN, and since the type is "SMTP" it wants to establish a TCP session with your mail server. You can likely test this out by opening up your command prompt and trying to telnet <MSExchangeWebServiceURL> 25. When that works, my guess is your code will work too.

How to tell if a URL is an intranet url?

Using C# how would one determine if a URL is an intranet URL? I would like some code to do something if a URL is an intranet one vs public.
you cannot implicitely know. if your intranet urls look like fully qualified domain names then it's difficult to tell. the only way to tell is to query two different DNS-servers (your own and a public one). If both return the same result, then it's an internet domain. if the public DNS-server isn't able to resolve the address, then it's most likely an intranet domain.
Do you know the internal subnets (in terms of IP addresses)? If so, I'd just resolve the host name and see if it's internal that way.
if the url resolves to a tcpIp address which is one of the IP addresses set aside as a private IPAddress, then it is definitely on your Intranet. these are
10.xxx.xxx.xxx,
172.16.xxx.xxx through 172.31.xxx.xxx, and
192.168.xxx.xxx
if it resolves to any other IP address it might still be on your intranet, but it has a public IP address so it is potentially accessible from outside the Intranet
The simple, and not perfect but works for the 80% case is to simply check if the URL has a period in it. I know Intranet URLs can be fully qualified, but in my experience (at Microsoft) most do not, and this works pretty well.
In general, there is no reliable way to tell an intranet URL from an Internet URL. If the intranet is available to your program, then it will look just like the Internet, and if not, then you still won't know whether the URL is supposed to be a working intranet URL or is just a (temporarily) broken Internet URL.
You will need some special knowledge, such as the domain names or IPs of the servers that are providing the intranet, in order to tell them apart.
If you want to determine whether any given URL is an intranet url in any company (as opposed to specializing your code for one particular company), I wish you luck.
Usually, but not always, itranet urls do not have a TLD (Top Level Domain, such as .com). However, I've seen some that do.
Almost always (AFAIK), intranet domains will resolve to a similar IP address as the computer's current address. Note that I did not say the same subnet; large intranets can have multiple subnets. Also note that if the computer is not in a corporate intranet, there will be regualr domain names that resolve to similar IP addresses. (Unless the computer is behind NAT)
I am not a C# programmer, so I can't offer you code, but the basic method would involve comparing the hostname part of the URL to that of server(s) in your intranet. Or, if your URL just uses an IP not a DNS name, compare the IP to that of your intranet server(s).
Crack the URL using string manipulation - though I imagine C# must have a URL class that will do this for you - and extract the hostname, compare it to a list of servers.
You could interrogate internet explorer to see if the domain would match the list of accepted intranet domains.
Registry key is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
There if the domain has a value for 1 for the protocol it will be deemed an intranet domain. You'll need to perform a nslookup to gather the 'real' address.
To add to what others have said, Intranet do not have any of the know top-level domain in its address. I've worked in a few companies and all the Intranet were something like:
http://developments/admin - you will notice that there's no top-level domain at all. So, it resolves to a computer within the network. Again, as the name suggests, you are not likely to access it beyond the corporate environment.

Categories

Resources