Shaul Behr
Shaul Behr

Reputation: 38023

What's the simplest & most efficient way of telling if your code is executing on the client or the server?

I have an ASP.NET (C#) class that is used both on the client and server.

Depending on whether the code is being executed on the client or the server, it needs to behave differently.

What is the simplest & most efficient way of telling if the code is executing on the client or the server?

Thanks!

Upvotes: 0

Views: 116

Answers (4)

MatthewMartin
MatthewMartin

Reputation: 33143

By your tags I see your talking about a web application not a client-server winforms app.

If it is in javascript, html and css, or silverlight it's happening in the browser. If it is happening in C#, it's happening on the server.

Upvotes: 2

Anton Gogolev
Anton Gogolev

Reputation: 115779

Unless we're talking Silverlight here, there's not much choice: C# code is always executed on the server, JavaScript is executed on the client.

Upvotes: 2

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422036

It's executing on the server. Unless you are using Silverlight, C# is probably not run on the client.

Upvotes: 2

AndreasKnudsen
AndreasKnudsen

Reputation: 3491

unless you are running Silverlight 2 or Silverlight 3 There is no way for Asp.Net to run C# code in the client (the users' browser)

Upvotes: 3

Related Questions