开发者

What's the cleanest way to create minimalistic ASPX page with Response.Write

开发者 https://www.devze.com 2023-04-03 23:57 出处:网络
I need to create a super small web interface which I could use to retrieve data f开发者_开发问答rom web server.

I need to create a super small web interface which I could use to retrieve data f开发者_开发问答rom web server.

Kinda like:

http://smartserver/?question=IsGrassGreen

With a response:

yes

I don't want, or need, to add all that soap envelope overhead, so I'm thinking of leaving the Default.aspx blank, aside from top line <%@ blablabla %>, viewstate disable, sessionstate disable, and that's it.

The question is, what do I have to do in codebehind? IIRC, Page_Load executes very far from entry point, and generates gobs of unnecessary processing, so there should be a better place to write Response.Clear, Response.Write, Response.Flush etc. But it has been 3+ years since I've done ASP.

Is there another, cleaner, smarter alternative to what I want to do?


To avoid the overhead of the Page Life Cycle, how about you implement an HTTP Handler for all requests and carry out the processing there?

  • Further documentation on MSDN
  • An example handler by Scott Hanselman


For a minimal website like this, we created an ASP.NET MVC website with no views at all. The controller simply returns plain old content.

Something like:

public class QuestionController : Controller
{
     public string ShowAnswer(string question)
     {
         // handle your logic
         return "yes";
      }
}

Then you can query your method by an URL like:

http://mysite/question/ShowAnswer/IsGrassGreen

Or you can take a look the Nancy framework.


You can use ASP.Net "WebMethod" to achieve your requirement in simple. This will avoid page cycles etc..

Refer this link
http://weblogs.asp.net/karan/archive/2010/09/12/calling-server-side-method-using-jquery-ajax.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消