Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Thursday, May 04, 2006

Check this out: http://atlas.asp.net/docs/util/srcview.aspx?path=~/atlas/samples/services/WebMethodOnPage.src.

Note that, within the .aspx page source, there is a method written in C# decorated with the [WebMethod] attribute. What this means is that you have a standard .aspx page hosting a webmethod, which is typically exposed only on .asmx (webservice) files. What's going on here?

As it turns out, this is a new feature in Atlas and it utilizes an unsupported method exposed within the ASP.Net runtime: Control.SetRenderMethodDelegate. The documentation is fairly self-explanatory:

Assigns an event handler delegate to render the server control and its content into its parent control.

What this means is that you can inject your own handler function to render any control or page in the runtime, thereby circumventing its own rendering code: extremely powerful, albeit sort of a hack. Now, the way this works in the Altas framework is this:

  1. The script module is loaded by the ASP.Net runtime due to its entry in the web.config file for the loading application.
    1. The .Init() method is called on the module, and it assigns a delegate for the PostMapRequestHandler event, OnPostMapRequestHandler.
  2. OnPostMapRequestHandler gets called and calls Microsoft.Web.Atlas.PageServiceHandler.HookUpPage() with the page the event was raised for as a parameter.
  3. The PageServiceHandler class registers its own PreRenderComplete event handler for the PreRenderComplete event for the page passed to it from earlier.
  4. The page goes through its normal life cycle and, right after the pre-render stage calls the PreRenderComplete handler method within the PageServiceHandler class.
  5. PageServiceHandler's implementation of PreRenderComplete includes calling .SetRenderMethodDelete() on the page if the page has, within its form post variables, the string "__serviceMethodName". The method passed as the handler is .Render from within PageServiceHandler.
  6. PageServiceHandler.Render gets called when the page is requested to render itself, and the implementation of said method is below:

private void Render(HtmlTextWriter output, Control container)
{
   Page page1 = (Page) container;
   WebServiceData data1 = WebServiceData.GetWebServiceData(page1.AppRelativeVirtualPath);
   string text1 = page1.Request.Form["__serviceMethodName"];
   WebServiceMethodData data2 = data1.GetMethodData(text1);
   string text2 = page1.Request.Form["__serviceMethodParams"];
   try
   {
      IDictionary<string, object> dictionary1 = JavaScriptObjectDeserializer.DeserializeDictionary(text2);
      object obj1 = data2.CallMethodFromRawParams(page1, dictionary1);
      string text3 = JavaScriptObjectSerializer.Serialize(obj1, data2.Owner);
      output.Write(text3);
   }
   catch (Exception exception1)
   {
      HttpContext context1 = HttpContext.Current;
      context1.Response.StatusCode = 500;
      context1.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(500);
      RestHandler.WriteExceptionJsonString(context1, output, exception1);
   }
}

Look carefully at the implementation and see the method data2.CallMethodFromRawParams() and the output.Write(), which combine to push out to the response stream the serialized HTTP response from the webmethod. The rabbit hole goes deeper and deeper, but it really does us no good to go much further as we know how to look for methods based on their attributes and dynamically execute them from within the .Net runtime. The secret has been cracked, effectively, and we see how they're intercepting the normal request for an .aspx page and re-routing it to a new Render handler which calls the proper method in the page class.

It is the responsibility of the client framework, then, to include within the form post variables the ever-important __serviceMethodName variable. If you take a Fiddler trace of a request to the webmethod using one of the Microsoft samples, you can see it clearly in there:

POST /docs/atlas/samples/services/WebMethodOnPage.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:
http://atlas.asp.net/docs/atlas/samples/services/WebMethodOnPage.aspx
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host: atlas.asp.net
Content-Length: 166
Proxy-Connection: Keep-Alive
Pragma: no-cache
Cookie: .....

__serviceMethodName=HelloWorld&__serviceMethodParams={"s":"asdfasdf"}&__VIEWSTATE=/wEPDwUKMjA4Mjk0NDk4M2Rk&nameTextBox=asdfasdf&__EVENTVALIDATION=/wEWAgLlssAyAouxhI4H


kick it on DotNetKicks.com
Thursday, May 04, 2006 4:09:23 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing
Tracked by:
http://freewebs.com/aspxfaq/01/sitemap14.aspx [Pingback]
http://freewebs.com/toltom/09/sitemap15.html [Pingback]
http://freewebs.com/toltom/12/aol-latino.html [Pingback]
http://freewebs.com/toltom/01/sitemap8.html [Pingback]
http://freewebs.com/toltom/07/blue-cross-blue-shield-florida.html [Pingback]
"http://fartooblog.tripod.com/174.html" (http://fartooblog.tripod.com/174.html) [Pingback]
"http://fartooblog.tripod.com/147.html" (http://fartooblog.tripod.com/147.html) [Pingback]
"http://xhasko.org/sitemap47.html" (http://xhasko.org/sitemap47.html) [Pingback]
"http://clxgxe.org/hot-college-lesbians.html" (http://clxgxe.org/hot-college-les... [Pingback]
"http://topslots.nl.eu.org/08/sitemap19.html" (http://topslots.nl.eu.org/08/site... [Pingback]
"http://freewebs.com/amexa/29/visions-credit-union.html" (http://freewebs.com/am... [Pingback]
"http://freewebs.com/amexa/26/the-daily-news-washington-nc.html" (http://freeweb... [Pingback]
"http://freewebs.com/amexa/38/world-tavern-poker.html" (http://freewebs.com/amex... [Pingback]
"http://pinofranc.homestead.com/03/halloween-9.html" (http://pinofranc.homestead... [Pingback]
"http://pinofranc.homestead.com/05/university-of-texas-medical-branch.html" (htt... [Pingback]
"http://pinofranc.homestead.com/03/www-property-appraiser-lee-fl-us.html" (http:... [Pingback]
"http://mdq3k-xxx.com/phoebe-cates-nude.html" (http://mdq3k-xxx.com/phoebe-cates... [Pingback]
"http://o4bwn-www.com/skinny-blonde-milf.html" (http://o4bwn-www.com/skinny-blon... [Pingback]
"http://tadguunews.netfirms.com/152.html" (http://tadguunews.netfirms.com/152.ht... [Pingback]
"http://zelkuunews.tripod.com/76.html" (http://zelkuunews.tripod.com/76.html) [Pingback]
"http://talpeenews.tripod.com/103.html" (http://talpeenews.tripod.com/103.html) [Pingback]
"http://kjipn-ooo.com/average-male-penis-size.html" (http://kjipn-ooo.com/averag... [Pingback]
"http://caploonews.tripod.com/98.html" (http://caploonews.tripod.com/98.html) [Pingback]
"http://xahrf-hhh.com/submissive-male.html" (http://xahrf-hhh.com/submissive-mal... [Pingback]
"http://zozpz-xxx.biz/sexy-videos.html" (http://zozpz-xxx.biz/sexy-videos.html) [Pingback]
"http://metnm-www.biz/www-asspussy.html" (http://metnm-www.biz/www-asspussy.html... [Pingback]
"http://kihub-eee.com/rave-girls-wild.html" (http://kihub-eee.com/rave-girls-wil... [Pingback]
"http://freewebs.com/amexa/48/verizon-virginia-beach-amp.html" (http://freewebs.... [Pingback]
"http://freewebs.com/amexa/11/pa-child-support.html" (http://freewebs.com/amexa/... [Pingback]
"http://freewebs.com/rimoq/17/luxury-hotels.html" (http://freewebs.com/rimoq/17/... [Pingback]
"http://freewebs.com/amexa/37/grandfather-mountain.html" (http://freewebs.com/am... [Pingback]
"http://freewebs.com/pentac/12/great-adventure.html" (http://freewebs.com/pentac... [Pingback]
"http://u1eah-rrr.com/men-desperate-to-pee.html" (http://u1eah-rrr.com/men-despe... [Pingback]
"http://unibetkom.150m.com/00879-blog.html" (http://unibetkom.150m.com/00879-blo... [Pingback]
"http://ramambo.nl.eu.org/12/slimfast.html" (http://ramambo.nl.eu.org/12/slimfas... [Pingback]
"http://ramambo.nl.eu.org/fairfax-county-federal-credit-union.html" (http://rama... [Pingback]
"http://ramambo.nl.eu.org/www-discoverytoys-com.html" (http://ramambo.nl.eu.org/... [Pingback]
"http://ddybkuh.biz/matthew-modine.html" (http://ddybkuh.biz/matthew-modine.html... [Pingback]
"http://ri9spbn.biz/penthouse-pets.html" (http://ri9spbn.biz/penthouse-pets.html... [Pingback]
"http://umuqjqf.com/high-school-fuck.html" (http://umuqjqf.com/high-school-fuck.... [Pingback]
"http://samotblog.nl.eu.org/realty.html" (http://samotblog.nl.eu.org/realty.html... [Pingback]
"http://faro--kom.nl.eu.org/rick-dees.html" (http://faro--kom.nl.eu.org/rick-dee... [Pingback]
"http://freewebs.com/gabeganews/1.html" (http://freewebs.com/gabeganews/1.html) [Pingback]
"http://hclu7dx.com/how-to-give-a-great-bj.html" (http://hclu7dx.com/how-to-give... [Pingback]
"http://dq8bbaq.biz/free-nude-anna-paquin.html" (http://dq8bbaq.biz/free-nude-an... [Pingback]
"http://dse--blog.nl.eu.org/yellow-pages.html" (http://dse--blog.nl.eu.org/yello... [Pingback]
"http://lnnv9gk.biz/nipples-squirting.html" (http://lnnv9gk.biz/nipples-squirtin... [Pingback]
"http://nasferablog.netfirms.com/24.html" (http://nasferablog.netfirms.com/24.ht... [Pingback]
"http://nk7g6ir.biz/jail-babes.html" (http://nk7g6ir.biz/jail-babes.html) [Pingback]
"http://nasferablog.netfirms.com/295.html" (http://nasferablog.netfirms.com/295.... [Pingback]
"http://ger--kom.nl.eu.org/masturbating-in-shower.html" (http://ger--kom.nl.eu.o... [Pingback]
"http://wbml1ig.biz/hetero-handjob.html" (http://wbml1ig.biz/hetero-handjob.html... [Pingback]
"http://jjyjxzl.biz/www-monarchgrandvacations-com.html" (http://jjyjxzl.biz/www-... [Pingback]
"http://jafert--niko.nl.eu.org/nude-native-american-indians.html" (http://jafert... [Pingback]
"http://nasferablog.netfirms.com/48.html" (http://nasferablog.netfirms.com/48.ht... [Pingback]
"http://jmqp7tr.biz/cardganes.html" (http://jmqp7tr.biz/cardganes.html) [Pingback]
"http://wwad6lf.biz/halidayinn.html" (http://wwad6lf.biz/halidayinn.html) [Pingback]
"http://derfoblog.ifrance.com/sitemap3.html" (http://derfoblog.ifrance.com/sitem... [Pingback]
"http://freewebs.com/sruone/york-air-conditioners.html" (http://freewebs.com/sru... [Pingback]
"http://freewebs.com/sruone/sitemap43.html" (http://freewebs.com/sruone/sitemap4... [Pingback]
"http://lopbafrea.homestead.com/164.html" (http://lopbafrea.homestead.com/164.ht... [Pingback]
"http://fm7fgw1.info/hotbot.html" (http://fm7fgw1.info/hotbot.html) [Pingback]
"http://freewebs.com/vuter/12/uc-irvine.html" (http://freewebs.com/vuter/12/uc-i... [Pingback]
"http://euter.homestead.com/01/bluecross-blue-shield-of-illinois.html" (http://e... [Pingback]
"http://buter.homestead.com/00/sitemap5.html" (http://buter.homestead.com/00/sit... [Pingback]
"http://cuter.homestead.com/00/cj-banks.html" (http://cuter.homestead.com/00/cj-... [Pingback]
"http://freewebs.com/datingblogger/1185.html" (http://freewebs.com/datingblogger... [Pingback]
"http://freewebs.com/datingblogger/1858.html" (http://freewebs.com/datingblogger... [Pingback]
"http://fasxen.netfirms.com/2.html" (http://fasxen.netfirms.com/2.html) [Pingback]
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)