Hi,

There is a possibility that the server reset and there is nobody that can log in to system. I dont want my webpage stop working at this state.so I want it do its main job.
The main job of this webpage(ASP.NET) is sending request to a client (via TCP socket) and receiving data from that client and save them into local sql server database.
how can I create this webpage? what technology can I use to do this?

Regards

Dani AI

Generated

Short answer: do not rely on an interactive desktop session. Run the long‑running TCP work as a service that starts at boot. A Windows Service (or a dedicated background process) will run without anyone logging on; an IIS-hosted ASP.NET page can also be up after boot but is not a reliable host for persistent socket listeners because app pools recycle and idle timeouts can drop connections.

Recommended approach and why

  • Put the TCP listener and SQL write logic into a Windows Service. Services are managed by the Service Control Manager and can be set to start automatically and recover on failure. This isolates the network/DB work from IIS lifecycle issues and from the need for an interactive logon. See .
  • If you must keep logic in IIS, use AppPool StartMode=AlwaysRunning and the Application Initialization feature, but treat IIS as a front end only; do not rely on it for high‑availability socket servers. See .

Practical steps

  1. Implement a service that hosts a TcpListener (or equivalent) and writes to SQL Server. Use a cancellation token and robust exception handling; persist partial data if needed.
  2. Configure the service startup to Automatic, give it an appropriate service account with DB access (or SQL credentials), and configure recovery actions to restart on failure.
  3. Open the required port(s) in Windows Firewall and verify with netstat. See TcpListener class and the firewall inbound rule guide above.

Minimal pattern (conceptual)

protected override void OnStart(string[] args)
{
  _cts = new CancellationTokenSource();
  Task.Run(() => StartListener(_cts.Token));
}

Troubleshooting and alternatives

  • Test by rebooting and checking Services.msc, Event Viewer, and netstat.
  • For periodic tasks (not continuous sockets), consider Task Scheduler with "Run whether user is logged on or not" instead. See Task Scheduler overview.
  • Thanks to for the pointer to socket basics; for production reliability, prefer the Windows Service pattern described above.

Recommended Answers

All 4 Replies

Thanks you for reply
but my main problem is not instant messaging. As I mention before :

"There is a possibility that the server pc (host) reset and there is nobody that can log in to system after reseting . I dont want my webpage stop working at this state until the Admin login to the server. so I want my webpage do its main job at logoff state of the server."

Regards

Is there anybody to help me?

is there anybody help me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.