Reputation: 20078
i am not a php guy so i am not sure what is doing here, can anybody help me convert this below code to .net?
PHP Process Page:
<?php
$Name = $_GET["Name"];
$Message = $_GET["Message"];
echo $_GET["jsoncallback"] . "({"Name": "" . $Name . "", "Message": "" . $Message . ""})";
?>
Upvotes: 0
Views: 488
Reputation: 218702
string strName=string.Empty;
string strMessage=string.Empty;
string strCallBack=string.Empty;
if(Request.QueryString["Name"]!=null)
{
strName=Request.QueryString["Name"];
}
if(Request.QueryString["Message"]!=null)
{
strName=Request.QueryString["Message"];
}
if(Request.QueryString["jsonCallback"]!=null)
{
strCallBack=Request.QueryString["jsonCallback"];
}
Response.Write(strCallBack+"({\"Name\":\""+strName+"\" ,\"Message\": "\"+strMessage+"\"})";
Upvotes: 0
Reputation: 13966
string Name = Request["Name"].ToString();
string Message = Request["Message"].ToString();
string jsoncallback = Request["jsoncallback"].ToString();
Response.Write( jsoncallback + "({'Name': '" + Name + "', 'Message': '" + Message + "'})" );
Upvotes: 3
Reputation: 498904
It simply gets the Name
and Message
parameters that were passed in to the page on the query string, then constructs a JSON string from them and outputs them.
In C#:
var name = Request.QueryString["Name"];
var message = Request.QueryString["Message"];
var json = Request.QueryString["jsoncallback"];
Response.Write(string.Format("{0}(\{\"Name\": {1}, \"Message\": {2} \})",
json, name, message));
VB.NET:
Dim name as String = Request.QueryString["Name"]
Dim message as String = Request.QueryString["Message"]
Dim json as String = Request.QueryString["jsoncallback"]
Response.Write(string.Format("{0}(\{\"Name\": {1}, \"Message\": {2} \})",
json, name, message))
Upvotes: 4
Reputation: 131811
Im not a .NET guy, but I understand whats there ;)
*$_GET* contains every query argument, so if you call this script via
http://example.com/script.php?Name=MyName&Message=Hello+World&jsoncallback=myCallback
*$_GET['Name']* (and then $Name) will contain "MyName", *$_GET['Messafe']* (and then $Message) will contain "Hello World" and *$_GET['jsoncallback']* "myCallback". So at all this script will return something like
myCallback({Name: MyName, Message: "Hello World"})
You can see the three values "myCallback", "MyName" and "Hello World" in there.
Upvotes: 1