Asp and WebClient: How to get dynamically actual host? [duplicate] - c#

This question already has answers here:
How to get "Host:" header from HttpContext (asp.net)
(4 answers)
Closed 8 years ago.
I want to get datas from an html file on my asp webserver, in Javascript to get actual host we can use the following:
~/mydatas.php
It gives on localhost: "http://localhost/mydatas.php"
I want the same thing but in C# can you help me?
Thanks you.

You could also search in stackoverflow and you will find a lot of answered question which had the same problematic than you. Like this one
Hopes it will help you !
Edit : You can use
HttpContext.Current.Request.Url.AbsoluteUri
It will give you the URL of your web page.

I've already try
HttpContext.Current.Request.Url.Host
which gives on localhost
:\windows\system32\inetsrv\localhost
...

Related

Asp.net Web API cant read file from file path [duplicate]

This question already has answers here:
ASP.NET MVC Website Read File from Disk Problem
(3 answers)
Closed 7 years ago.
I am developing an azure asp.net web api 2 ,and in my api i am trying to read a dataset ,however i couldnt get my dataset.csv path.I connect to ftp server and i found the rout is : ..../site/wwwroot/dataset.csv this ,
I tried this
string path = "/site/wwwroot/dataset.csv";
and also this
string path=Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, "dataset.csv");
however none of them is working i couldnt read the data file , how can i read it ?
Thanks
Try using System.Web.HttpContext.Current.Request.MapPath() instead:
string path=System.Web.HttpContext.Current.Request.MapPath("~\\dataset.csv");
Oh, and a friendly ask: please search StackOverflow before posting questions - this has been asked and answered here

Selenium Web Page in Text Search [duplicate]

This question already has answers here:
Finding text on page with Selenium 2
(4 answers)
Closed 8 years ago.
How can I make a text call using selenium on a web page?
Should I use searchContext?
I tried using xpath but I get an error.
//***********************
okay all thanks. my code is working :)
var link = _driver.FindElement(By.XPath("//*/a[contains(.,'btctrader')]")).Text;
Well, this will check if text exists on the page:
driver.getPageSource().contains("Text");
But this is just one of many ways. You'd need to be more specific if this is not what you're looking for.

Find out from which url your API called [duplicate]

This question already has an answer here:
Get URL of Referer page in ASP.NET
(1 answer)
Closed 8 years ago.
I'm using web api.My question is: I have to check from where call is coming in Global.asax(Application_AcquireRequestState) because I have to restrict some calls which are coming from unknown urls for the purpose of web api security.
You can use Request.UserHostAddress to get the IP address from which the call is coming and Request.UrlReferrer to get the URL that linked to the current URL.

ASP.NET c# Profile: GetProfile not avalaible [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to use Profile.GetProfile() in a library class?
How to get profile in a cs class? It works fine in aspx.cs class.
ProfileCommon profile= HttpContext.Current.Profile.GetProfile(username);
How to make GetProfile() available in cs class? please advice, Thank you
Take a look at my answer about profiling users. There is all you need:
User profiles in asp.net

Adding a separate file for all website content [duplicate]

This question already has an answer here:
Getting text from the Resource file in asp.net 4
(1 answer)
Closed 8 years ago.
Thank you in advance for your help.
I have a website in asp.net and c#, i need to have it that all text that is in the site should be taken from a separate file, so it can be changed easily if needed, and for other similar reason.
Hope this id clear.
What is the best way of doing such a thing?
You'll want to read up on resource files, globalisation & localisation. There is a binding expression, similar to <%# that can read the values from the resource files.
This should get you started: http://msdn.microsoft.com/en-gb/library/fw69ke6f.aspx
Simon
I would be tempted to keep your solution 'un-compiled' and then use resource files.

Categories