Need php snippet converted to asp.net

St_Aug_Beach_Bum
St_Aug_Beach_Bum used Ask the Experts™
on
I deliver content to other websites through a small php snippet.  I have other webmasters put this on their site:

<?
//code for the Clock
$rqst=$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];
$url="http://www.mysite.com/data/wwc.php?rqst=".$rqst;
@readfile($url);
?>

I have request from users that would like to have that in asp.net #C code.  Can you convert it?

Also (I don't know anything about asp.net other than it's server side for windows), does asp.net #C work on any asp.net host, or does the #C mean it only works on asp.net #C hosts? Probably a stupid question, but I just don't know these things...

Thanks for any help,  Chris
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I'm amazed that can't do this themselves... But, something along the lines the following:

FYI :) - C# Server variables and PHP ones:
Request.ServerVariables(SERVER_NAME); same as $_SERVER["HTTP_HOST"];
Request.ServerVariables(SCRIPT_NAME); same as $_SERVER["PHP_SELF"];
Request.ServerVariables(HTTP_USER_AGENT); same as $_SERVER["HTTP_USER_AGENT"];
Request.ServerVariables(REMOTE_ADDR); same as $_SERVER["REMOTE_ADDR"];
Request.ServerVariables(HTTP_REFERER); same as $_SERVER["HTTP_REFERER"];

call the function below like (or into a var if they want they will know what to do);

<%
string host = Request.ServerVariables(SERVER_NAME); same as $_SERVER["HTTP_HOST"];
string self = Request.ServerVariables(SCRIPT_NAME); same as $_SERVER["PHP_SELF"];
string rqst =host+self;
string url ="http://www.mysite.com/data/wwc.php?rqst="+rqst;
Response.Output.Write(GetContent("http://oldlook.experts-exchange.com/"))
%>

Now for the function...
<%
        string GetContent( string url)
        {
            string result = "Error communicating with server";
            System.Net.HttpWebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            wreq.Method = "GET";
            wreq.Timeout = 3000;
            System.Net.HttpWebResponse wr = (System.Net.HttpWebResponse)wreq.GetResponse();
 
            if (wr.StatusCode == System.Net.HttpStatusCode.OK)
            {
                System.IO.Stream s = wr.GetResponseStream();
                System.Text.Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
                System.IO.StreamReader readStream = new System.IO.StreamReader( s, enc );
                result = readStream.ReadToEnd();
            }
            return result;
        }
%>

Open in new window

Commented:
answer to above is generally yes :)
Hi Chris
I don't do PHP and you don't do asp.net.
However this is only a few lines of code I'm sure we can work this out.
Can you convert your code to an algorithm in plain English and then I'll write it in asp.net for you.
 
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
Hi,

Thank you all very much, sorry I didn't get back to this thread yesterday, been dealing with a sick 6 year old.

BrianMM, thank you, what I need to do, if possible (I don't know what's possible in asp.net), is have it shorter, so it's just one thing someone can easily take and cut and paste into their html (I'm trying to keep it insanely simple for them).  If having a function like that is what needs to be done though, I'll manage.

daveamour, basically all I need to do is get the url of the page the script is on (this will be $rqst).

Then fetch and display the contents of the file:  http://www.mysite.com/data/wwc.php?rqst=www.theURLdisplayingTheContent.com

The contents of the file will be a table with the tool or data in it.

For example, the file would be something like this (we can use this as a test):

http://www.sure-start.com/test.php?rqst=requestingURL.com

and someone should be able to fetch this file with asp.net and display it on their page.




Commented:
I'm afraid thats as short as it will be in .NET, they need to include that function somewhere and then they can call it where needed. The call itself is a one-liner... but unfortinatley the code required to replicate what PHP does is as above!

Author

Commented:
BrianMM,

Thank you, sorry it took me so long to get back and try this out and assign points, been sick as a dog with the flu.

Thank you for the help!  

Chris

Commented:
were you going oink? :)

Author

Commented:
Just about!  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial