Click here to Skip to main content
13,258,269 members (46,261 online)
Rate this:
Please Sign up or sign in to vote.

I'm new to the ASP .NET technology (but much acquainted to other .NET technologies like C#). I would like to know whether (and how) is it possible to execute C# code simply when the page loads, given all the relevant data from the HTTP request (pass POST information to it). and simply write the returned string back in the HTTP response.

Thanks a lot for helping.
Posted 13-Oct-12 3:45am
n.podbielski 13-Oct-12 8:51am
On server side or client side?
Do you mean like web page will load in browser? Then you want to run some server code?
ShacharK 13-Oct-12 9:04am
I would like to write minimal amount of ASP code.
I have no real need for any web features provided by the HTTP protocol.
I use the http server as a platform to have clients communicating with my database using my custom JSON-based protocol.
You send a request, My protocol which I want to implement in C# processes information, makes the desired API Calls, and prints out a simple JSON-object response (instead of an actual website's html)
thewazz 13-Oct-12 10:18am
this help?
n.podbielski 13-Oct-12 14:35pm
Then why wont you just use JSON enabled WCF service?
ShacharK 14-Oct-12 16:12pm
Would that be better? Isn't WCF an overkill? I always found this technology far too complicated for any of my needs in the past. I would love to hear your opinion.
n.podbielski 15-Oct-12 1:11am
It is complicated if you want to run it exactly as you want. But you can also click-add-create it in vs. Ide will do everything for you.
With json it is more demanding depending of how you want to call this service. If from .net site you can just add service reference from vs. If from example jQuery it is more complicated. Last time i was creating service i spend few hours just for configuring from which url this will be executed :)
Write from where you would want to call this solution.

Again wcf is complicated but also very powerful. So i think this wil be less error prone then your custom solution. For starter you have many things out of the box (authorization, serialization, deserialization, js scripts, data validation etc.) which in your solution you will have to make yourself.

Yes you can also just add app to your iss. Delete html from default.aspx and in page load deserialize some parameter to object calculate something and return another object serialized as JSON with Response.Write
It will be simple and it will work after 1 hour so again it depends what you want.

But if it will have to be more complicated i would add WCF service just to learn how to do that. Its popular technology so experience with it will not hurt.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The simple approach: in Page_Load event (pertinent to ASP.NET server side) use !IsPostBack property that indicates the first page load.

Read more on this topic here:[^]


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100