Hello, Mike.
To answer your first question, blank value of the "HTTP_USER_AGENT" service variable is the right way to tell between a browser and "everyone else". Blank value is not guaranteed to be uniquely Cassini's - any .NET application using WebRequest to call your application will have blank user agent value. Therefore, we have logged a feature request to make Cassini supply its own user agent value.
We suggest using following code snippet to make it future-proof:
Code:string userAgent = this.Request.ServerVariables["HTTP_USER_AGENT"];
bool cassi--- !!!SPAM!!! ---epInMemoryPinger = string.IsNullOrEmpty(userAgent) || userAgent.ToLower().Contains("ultidev");
// Use cassi--- !!!SPAM!!! ---epInMemoryPinger flag to tell regular browser from Cassini.
Regarding your second question, to tell whether it's the first ping or a subsequent, you would have a code something like this:
Code:// class member declaration, likely of Default.aspx.cs
volatile private static bool isFirstCassiniPing = true;
...
// Ping request handler - probably Page_Load() of the Default.aspx.cs
if(cassi--- !!!SPAM!!! ---epInMemoryPinger && isFirstCassiniPing)
{
isFirstCassiniPing = false;
// your logic
}
Please let us know if this information was helpful.
Best regards,
UltiDev Team.
Please donate at
http://www.ultidev.com/products/Donate.aspx to help us improve our products.