Get Client Machine ID - c#-2.0

I need to get Client's Machine ID and their Country in my web application...
Is it possible get succeed in this?

using System.Globalization;
string culture = CultureInfo.CurrentCulture.EnglishName;
string country = culture.Substring(culture.IndexOf('(')
+ 1, culture.LastIndexOf(')') - culture.IndexOf('(')-
Client Country in C#
Get Client Computer Name,
How to get the client machine name from a server
You will get most of the details of
the client machine using the
"Request.ServerVariables"
// Try the following C# code
System.Net.IPHostEntry host = new System.Net.IPHostEntry();
host = System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_HOST"]);
lbl.Text = host.HostName;

Host name:
Request.ServerVariables["REMOTE_HOST"]
See http://www.w3schools.com/asp/coll_servervariables.asp
Resolve country:
public static RegionInfo ResolveCountry()
{
CultureInfo culture = ResolveCulture();
if (culture != null)
return new RegionInfo(culture.LCID);
return null;
}
from http://madskristensen.net/post/Get-language-and-country-from-a-browser-in-ASPNET.aspx
This uses the PC's setup Language/Country.
By IP try an example at:
http://dotnetguts.blogspot.com/2008/06/finding-country-from-visitors-ip-in.html
Which involves checking the requesting IP adresses against a database of IP locations.
You could also use an IP for a service that already supports this such as:
http://www.ipgeo.com/api/

Related

Remote Name Can't Be Resolved accountname.blob.core.windows.net

I have an ASP.NET MVC application that connects to Azure blob storage; locally everything is fine and I can connect to blob storage and access my containers and list blobs, but once deployed I get this error:
Azure.RequestFailedException: The remote name could not be resolved: 'MyAccountName.blob.core.windows.net'
Does anyone have an idea how to solve this error?
Here is the container code for connecting to the Azure Blob
public ActionResult QuickPhotos()
{
string storageConnectionString = ConfigurationManager.ConnectionStrings["AZURE_STORAGE_CONNECTIONSTRING"].ConnectionString;
string containerName = "infoimages";
BlobContainerClient blobContainerClient = new BlobContainerClient(storageConnectionString, containerName);
List<string> Images = new List<string>();
foreach (BlobItem item in blobContainerClient.GetBlobs())
{
Images.Add("https://azureblob.interstellarseries.com/" + containerName +"/"+item.Name);
}
return View(Images);
}
It looks like you have wrong account name in connection string,
you should have:AccountName=Your Account Name,
instead of:
AccountName=Your Account name.blob.core.windows.net
For more details check with this link

Where to place code for global access in MVC multi tenant application

.Net 4.6.1 MVC
I placed the following test code in the Index action of the HomeController to test deciphering of the Host name for multi tenancy.
Where should the code be placed so that the Host or Tenant info can be accessible globally in the application?
Once the host or tenant is obtained from the URL and host data retrieved from the database should the data be stored in a session or retrieved with every request?
string host = string.Empty;
host = Request.Url.Host;
int portNumberIndex = host.LastIndexOf(':');
if (portNumberIndex > 0)
{
host = host.Substring(0, portNumberIndex);
}
ViewData["hostName"] = host;

Clarification required about PrincipalContext security permissions and PrincipalContext's ContextType.Machine

using (PrincipalContext Context = new PrincipalContext(ContextType.Domain, DomainURL, UserName, Password))
{
UserPrincipal Account = new UserPrincipal(Context);
Account.GivenName = strFirstName;
Account.Surname = strLastName;
PrincipalSearcher srch = new PrincipalSearcher(Account);
foreach (var principal in srch.FindAll())
{
var p = (UserPrincipal)principal;
String FirstName = p.GivenName;
String LastName = p.Surname;
}
}
If i use the code above to query Active Directory and the UserName(account) passed in the PrincipalContext constructor is in a domain that has no trust with the target domain(domain to be queried), i get the below error.
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted. ---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.
Would i be correct to assume that if the PrincipalContext construct was changed to,
using (PrincipalContext ctx = new PrincipalContext(ContextType.Machine))
the code would execute successfully as long as the client is in the target domain?
Lets assume the first code with UserName and Password was called by a client in domain A trying to search for user info in domain B, here establishing context failed because the account used is in domain A that has no trust with domain B.
am i correct to assume that if i change the ContextType to Machine, and the client calling the code is in domain B, the code would execute succefully?
No, that would not be a correct assumption. ContextType.Machine means that you want to work with local accounts.
Your PrincipalSearcher will end up searching the local SAM database rather than Active Directory

Facebook OAuth + AppHarbor workaround on random port

I a have a sample app, hosted on AppHarbor and now want to integrate authorization through facebook. So i downloaded nugget Facebook.Web.Mvc package to implement it.
After reading tutorial, in controller i have method:
public ActionResult Login(string returnUrl)
{
var oauthClient = new FacebookOAuthClient(FacebookApplication.Current) { RedirectUri = GetFacebookRedirectUri() };
if (!string.IsNullOrWhiteSpace(returnUrl))
{
returnUrl = Url.Action("Index", "Facebook");
}
dynamic parameters = new ExpandoObject();
parameters.scope = ExtendedPermissions;
var state = new { csrf_token = CalculateMD5Hash(Guid.NewGuid().ToString()), return_url = returnUrl };
parameters.state = Base64UrlEncode(Encoding.UTF8.GetBytes(JsonSerializer.Current.SerializeObject(state)));
SetFacebookCsrfToken(state.csrf_token);
string s = oauthClient.GetLoginUrl(parameters).AbsoluteUri;
ViewBag.FacebookLoginUrl = s;
//new LogEvent(s).Raise();
return View(new AccountModel());
}
View:
<a href="#ViewBag.FacebookLoginUrl" id="lUrl">
<div class="fblogin"></div>
In localhost this works for me.
But when i upload it to appharbor, i see, that generated link indicates to address + port 16013 (as support told always random port). So clicking it shows me facebook login window, than blank page.
I manually configured my app settings in facebook to this port but it did not helped.
Also i tried to access my site through this port - nothing.
Then i changed port number through jquery to 80, its also did not help.
you have had such problems?
I'm not familiar with the Facebook api, but I've had a similar problem.
I suspect that the returnUrl value being passed in is incorrect. It probably contains a port number that AppHarbor uses internally for load balancing.
See this article on how to create a public url for AppHarbor:
http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number
Then make sure that the value in your returnUrl is publicly available.
You can now set the aspnet:UseHostHeaderForRequestUrl appSetting to true which effectively solves this problem. This can be done by adding a Configuration Variable to your application with the corresponding key and value.
Source on AppHarbor

getting ip address from host name in BlackBerry 6

Please let me know whether there is way to get the IP address of server from it's domain name.
for example:
Domain name is : http://www.gmail.com
then i want api like
public String getIPAddress(String hostname)
{
Some code here
return ipAddress;
}
I am using Blackberry 6 api, which does not have InetAddress class.
I dont think there is an API available in BB
http://supportforums.blackberry.com/t5/Java-Development/is-there-a-way-to-get-the-remote-ip-address-given-its-hostname/td-p/171164

Resources