Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to call a specific server-side method?

Reply
Thread Tools

How to call a specific server-side method?

 
 
Cyphos
Guest
Posts: n/a
 
      11-03-2005
Hi,

I'm just learning how to use the XmlHttpRequest object. Very cool.
However, I'm wondering how I can call a specific server-side method.
For example, say I have a method defined as follows on an ASP.NET
code-behind file

public string GetServerTime()
{
return DateTime.Now.ToShortTimeShort();
}

Would I have to change the request method to POST? Could someone post
an example please? Or can I simply not call a method, and have to call
the method from the Page_Load event?

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-03-2005
Cyphos wrote:

> I'm just learning how to use the XmlHttpRequest object. Very cool.
> However, I'm wondering how I can call a specific server-side method.


You cannot do that directly.

> For example, say I have a method defined as follows on an ASP.NET
> code-behind file
>
> public string GetServerTime()
> {
> return DateTime.Now.ToShortTimeShort();
> }
>
> Would I have to change the request method to POST? Could someone post
> an example please? Or can I simply not call a method, and have to call
> the method from the Page_Load event?


Either question has to be answered with: You have not yet understood how
XMLHTTPRequest works. Here it is in short: it sends a request to a host
which is running a HTTP server, returns information about the request
status and the server reply. Nothing more, nothing less.

So if you want to call a specific server-side method, that has to be done
server-side in an (ASP.NET) application that is executed when the specific
resource is requested, such as

<%@ LANGUAGE = JScript %>
<%= GetServerTime() %>

(Even though the interface is named XMLHttpRequest, you do not need to
return XML content; any output will do.)


HTH

PointedEars
 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      11-03-2005
Cyphos wrote:

> I'm just learning how to use the XmlHttpRequest object. Very cool.
> However, I'm wondering how I can call a specific server-side method.


You would have to construct which would cause the server side script to
execute that method. This is most easily achieved by specifing it in the
query string (and altering the server side script to check that query
string parameter).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-03-2005
David Dorward wrote:

> Cyphos wrote:
>> I'm just learning how to use the XmlHttpRequest object. Very cool.
>> However, I'm wondering how I can call a specific server-side method.

>
> You would have to construct which would cause the server side script to
> execute that method. This is most easily achieved by specifing it in the
> query string (and altering the server side script to check that query
> string parameter).


Which of course would be potentially dangerous since an attacker
could then probably execute arbitrary code server-side:

http://foo.bar/baz.asp?delete_all_files%28%29


PointedEars
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-03-2005
Thomas 'PointedEars' Lahn said the following on 11/3/2005 4:21 AM:

> David Dorward wrote:
>
>
>>Cyphos wrote:
>>
>>>I'm just learning how to use the XmlHttpRequest object. Very cool.
>>>However, I'm wondering how I can call a specific server-side method.

>>
>>You would have to construct which would cause the server side script to
>>execute that method. This is most easily achieved by specifing it in the
>>query string (and altering the server side script to check that query
>>string parameter).

>
>
> Which of course would be potentially dangerous since an attacker
> could then probably execute arbitrary code server-side:
>
> http://foo.bar/baz.asp?delete_all_files%28%29


Only if you are stupid enough to allow it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      11-03-2005

Cyphos wrote:
> Hi,
>
> I'm just learning how to use the XmlHttpRequest object. Very cool.
> However, I'm wondering how I can call a specific server-side method.
> For example, say I have a method defined as follows on an ASP.NET
> code-behind file
>
> public string GetServerTime()
> {
> return DateTime.Now.ToShortTimeShort();
> }
>
> Would I have to change the request method to POST? Could someone post
> an example please? Or can I simply not call a method, and have to call
> the method from the Page_Load event?


You can use WebService behavior:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp>

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      11-04-2005
Thomas 'PointedEars' Lahn wrote:

>> You would have to construct which would cause the server side script to
>> execute that method. This is most easily achieved by specifing it in the
>> query string (and altering the server side script to check that query
>> string parameter).


> Which of course would be potentially dangerous since an attacker
> could then probably execute arbitrary code server-side:
>
> http://foo.bar/baz.asp?delete_all_files%28%29


Easily avoided... Just don't include the code:

if ($action eq "delete_all_files") {
system('rm -rf /');
}


--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-04-2005
David Dorward wrote:

> Thomas 'PointedEars' Lahn wrote:
>>> You would have to construct which would cause the server side script to
>>> execute that method. This is most easily achieved by specifing it in the
>>> query string (and altering the server side script to check that query
>>> string parameter).

>
>> Which of course would be potentially dangerous since an attacker
>> could then probably execute arbitrary code server-side:
>>
>> http://foo.bar/baz.asp?delete_all_files%28%29

>
> Easily avoided... Just don't include the code:
>
> if ($action eq "delete_all_files") {
> system('rm -rf /');
> }


Which proves my point. GET is dangerous here. POST ist less dangerous.
Even less dangerous would be something like a confirmation document or
server-side sessions or ...


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
XML parsing problem finding a specific element in a specific place mazdotnet ASP .Net 2 10-02-2009 10:07 AM
Is ViwState Page-Specific or UserControl-Specific =?Utf-8?B?SmF2?= ASP .Net 2 08-16-2006 09:30 PM
redirect traffic on specific ip to specific interface mimiseh Cisco 3 06-05-2005 09:14 PM
How do you make sure a frameset is loaded? I'm trying to open a frameset in a new window which shows a specific html page in a specific frame ck388 Javascript 1 09-24-2003 08:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57