Finally got it working
Many thnaks to Jaws and Durbs
private string getHostName()
{
string hName = "";
System.Net.IPHostEntry host = new System.Net.IPHostEntry();
host = System.Net.Dns.GetHostEntry(HttpContext.Current.Re quest.ServerVariables["REMOTE_HOST"]);
//Split out the host name from the FQDN
if (host.HostName.Contains("."))
{
string[] sSplit = host.HostName.Split('.');
hName = sSplit[0].ToString();
}
else
{
hName = host.HostName.ToString();
}
return hName;
}
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "C#.NET getting remote host name (not web server name)"
Collapse
-
System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName
(currently on my Mac so cant try the above though to check it works)
Edited, doh, just realised you'd tried that one! Maybe:
Dim host As System.Net.IPHostEntry
host = System.Net.Dns.GetHostByAddress(Request.ServerVari ables.Item("REMOTE_HOST"))
strComputerName = host.HostName
Or if you like lots of brackets and semicolons, summat like:
System.Net.IPHostEntry host;
host = System.Net.Dns.GetHostEntry(HttpContext.Current.Re quest.ServerVariable["REMOTE_HOST"]);
string strComputerName = host.HostName;
Response.Write("PC Name is: " + strComputerName);Last edited by Durbs; 26 July 2010, 18:55.
Leave a comment:
-
Originally posted by wxman View PostI have a bit of a problem. I am trying to get hold the PC hostname for an intranet questionnaire application I am writing.
Basically I need to ensure that the user can only submit the form once. I was planning to capture the users computer name and store that against the record. The user does not log in to the web form in any way, just request the URL from the web server.
However every thing I do just returns the hostname of the Web Server- not the client. I am totally stuck!!
I have tried all the following :-
Environment.MachineName;
System.Net.Dns.GetHostName();
System.Environment.GetEnvironmentVariable("COMPUTE RNAME");
HttpContext.Current.Request.UserHostName;
System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName.ToString();
Has any one got any suggestion?
The head of HR is hounding me to complete this, hence the reason why I am looking at it on a sunday afternoon!
Given what you have, I'd probably just store something in a cookie to signify completion of the form because these are unique to a user's profile. Although if they deleted their cookies they'd obviously be able to recomplete the form. I suppose you have that risk if they log in to another machine with the host name approach.
Most intranet servers I've worked on have been configured to run under windows authentication, so as long as it was enabled in the web.config you could get to the user name via "HttpContext.Current.User".
Leave a comment:
-
C#.NET getting remote host name (not web server name)
I have a bit of a problem. I am trying to get hold the PC hostname for an intranet questionnaire application I am writing.
Basically I need to ensure that the user can only submit the form once. I was planning to capture the users computer name and store that against the record. The user does not log in to the web form in any way, just request the URL from the web server.
However every thing I do just returns the hostname of the Web Server- not the client. I am totally stuck!!
I have tried all the following :-
Environment.MachineName;
System.Net.Dns.GetHostName();
System.Environment.GetEnvironmentVariable("COMPUTE RNAME");
HttpContext.Current.Request.UserHostName;
System.Net.Dns.GetHostEntry(Request.ServerVariable s["remote_addr"]).HostName.ToString();
Has any one got any suggestion?
The head of HR is hounding me to complete this, hence the reason why I am looking at it on a sunday afternoon!Tags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Streamline Your Retirement with iSIPP: A Solution for Contractor Pensions Sep 1 09:13
- Making the most of pension lump sums: overview for contractors Sep 1 08:36
- Umbrella company tribunal cases are opening up; are your wages subject to unlawful deductions, too? Aug 31 08:38
- Contractors, relabelling 'labour' as 'services' to appear 'fully contracted out' won't dupe IR35 inspectors Aug 31 08:30
- How often does HMRC check tax returns? Aug 30 08:27
- Work-life balance as an IT contractor: 5 top tips from a tech recruiter Aug 30 08:20
- Autumn Statement 2023 tipped to prioritise mental health, in a boost for UK workplaces Aug 29 08:33
- Final reminder for contractors to respond to the umbrella consultation (closing today) Aug 29 08:09
- Top 5 most in demand cyber security contract roles Aug 25 08:38
- Changes to the right to request flexible working are incoming, but how will contractors be affected? Aug 24 08:25
Leave a comment: