<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx</link><description>Ah, yes... GetServerVariable is one of the most frequently used function call of ISAPI Extension and ISAPI Filter APIs, but unfortunately, it is also one of the most incorrectly used. Very few people heed the documentation to check the return value and</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453539</link><pubDate>Fri, 19 Aug 2005 11:13:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453539</guid><dc:creator>Louis</dc:creator><description>David,&lt;br&gt;&lt;br&gt;thank you for your view on the subject!&lt;br&gt;&lt;br&gt;This morning I found a solution to the problem.&lt;br&gt;When I set the Isolation Mode for IIS6.0 to the IIS5.0 compatibility mode, the problem is gone.&lt;br&gt;&lt;br&gt;It clears the fact that the GetServerVariable could be used incorrectly. But why does it not work in IIS6.0 Isolation mode? &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453555</link><pubDate>Fri, 19 Aug 2005 12:18:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453555</guid><dc:creator>David Wang</dc:creator><description>Can you give whether this is on Windows Server 2003 RTM, with patches, or SP1.&lt;br&gt;&lt;br&gt;Also, please give the other five pieces of information that I identified at the top of this blog entry (exact server variable name, buffer sizes, return value of GetServerVariable, and if FALSE, value of GetLastError()).&lt;br&gt;&lt;br&gt;Finally, is the GetServerVariable() call made in an ISAPI Filter on ISAPI Extension? And if it is made from a filter, in what filter event(s)?&lt;br&gt;&lt;br&gt;Without this basic information, it will be difficult to determine what you are observing. &lt;br&gt;&lt;br&gt;For example, some server variable values are invalid and others may not be available, depending on IIS6 process model. But, I am not going to guess -- If you do not tell me exactly what you are doing, I cannot give any more information.&lt;br&gt;&lt;br&gt;//David</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453589</link><pubDate>Fri, 19 Aug 2005 14:29:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453589</guid><dc:creator>Louis</dc:creator><description>Hi David,&lt;br&gt;&lt;br&gt;i've asked the programmer to look at this posting. I hope you two will figure it out ;-)&lt;br&gt;&lt;br&gt;The server i'm using is Windows 2003 WebEdition SP1 with all the Patches installed.&lt;br&gt;&lt;br&gt;The ISAPI is an Extension and the ServerVariable I want is configurable. So I can ask through the ISAPI whatever variable I want.&lt;br&gt;&lt;br&gt;regards,&lt;br&gt;&lt;br&gt;Louis</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453597</link><pubDate>Fri, 19 Aug 2005 15:11:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453597</guid><dc:creator>Louis</dc:creator><description>Ok... this one is going to make is more difficult.&lt;br&gt;&lt;br&gt;I told you earlier that I was running a WebEdition. I am, but I was testing the Isolation mode with a Windows 2003 SBS.&lt;br&gt;&lt;br&gt;The ISAPI works on the Windows 2003 SBS with IIS5.0 Isolation mode active.&lt;br&gt;&lt;br&gt;The ISAPI does not work on the WebEdition either with or without the Isolation mode active.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453755</link><pubDate>Fri, 19 Aug 2005 21:31:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453755</guid><dc:creator>David Wang</dc:creator><description>Louis - since I am trying to help you, but you refuse to give me the information I need, there is nothing more I can do.&lt;br&gt;&lt;br&gt;I consider this a non-issue until you can provide substantial information to prove otherwise.&lt;br&gt;&lt;br&gt;//David</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453767</link><pubDate>Fri, 19 Aug 2005 22:01:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453767</guid><dc:creator>Louis</dc:creator><description>And I thank you for your help!!&lt;br&gt;&lt;br&gt;Here are some answers to your questions, provided by the programmer. &lt;br&gt;&lt;br&gt;If you need more, I'll notice! ;-)&lt;br&gt;&lt;br&gt;1. The exact name of the ServerVariable being retrieved.&lt;br&gt;&lt;br&gt;    &amp;quot;SERVER_NAME&amp;quot;, &amp;quot;LOCAL_ADDR&amp;quot;, &amp;quot;PATH_INFO&amp;quot;, etc.&lt;br&gt;&lt;br&gt;2. The value of the buffer pointer. Is it NULL or points to valid memory.&lt;br&gt;&lt;br&gt;    In the call, it is just &amp;quot;buf&amp;quot;, where buf is an automatic variable&lt;br&gt;    declared in the function as:&lt;br&gt;       char  buf[MAX_SERVER_VAR];&lt;br&gt;    and MAX_SERVER_VAR has been defined as:&lt;br&gt;       #define MAX_SERVER_VAR 2048&lt;br&gt;    (If the call is successful, the data is moved to dynamically&lt;br&gt;    allocated memory of the necessary size.)&lt;br&gt;&lt;br&gt;3. The value of the DWORD being passed in. Is it 0 or something else&lt;br&gt;&lt;br&gt;    In the call, it is &amp;quot;&amp;amp;size&amp;quot;, where size is initialized in the&lt;br&gt;    declaration as:&lt;br&gt;       DWORD size = MAX_SERVER_VAR;&lt;br&gt;    (This is an automatic variable in a function that retrieves a&lt;br&gt;    single server variable, so it is declared on each call.)&lt;br&gt;&lt;br&gt;4. The return value from the GetServerVariable call. Is it TRUE or FALSE&lt;br&gt;&lt;br&gt;    FALSE&lt;br&gt;&lt;br&gt;5. If the return value is FALSE, what does GetLastError() return?&lt;br&gt;&lt;br&gt;    ERROR_INVALID_INDEX (which the function reports as &amp;quot;ERROR: undefined&lt;br&gt;    server variable&amp;quot;).&lt;br&gt;&lt;br&gt;</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#453936</link><pubDate>Sat, 20 Aug 2005 05:22:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453936</guid><dc:creator>David Wang</dc:creator><description>1. Since you have the name parameterized on the GetServerVariable() call, are you sure that named string is NULL-terminated when used by GetServerVariable().&lt;br&gt;2. Is the server variable name all upper-case (since you are parsing out a parameterized value).&lt;br&gt;3. Any other stray random characters involved with the parameterized name - what happens if you try a fixed value for the variable name like &amp;quot;SERVER_NAME&amp;quot; (or whatever fails for you) in your ISAPI (and change no other code) - does that work or not.&lt;br&gt;&lt;br&gt;//David</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#455152</link><pubDate>Tue, 23 Aug 2005 19:16:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:455152</guid><dc:creator>Louis</dc:creator><description>David,&lt;br&gt;&lt;br&gt;sorry for the delay&lt;br&gt;&lt;br&gt;1. Since you have the name parameterized on the GetServerVariable() call, are you sure that named string is NULL-terminated when used by GetServerVariable(). &lt;br&gt;&lt;br&gt;The variable names are not parameterized; they are null-terminated strings. &lt;br&gt;&lt;br&gt;2. Is the server variable name all upper-case (since you are parsing out a parameterized value). &lt;br&gt;&lt;br&gt;&amp;quot;One problem I found with the ISAPI under IIS 6.0 was that server variable names need to be all uppercase, so my function case-shifts the name that's passed in before calling GetServerVariable. The script works on other IISs (and on the system where it doesn't &lt;br&gt;work, the CGI version running that same script can get the &amp;quot;environment&amp;quot; variables by those names), it would appear that you have the names correct, with no extraneous characters.&lt;br&gt;&lt;br&gt;&lt;br&gt;3. Any other stray random characters involved with the parameterized name - what happens if you try a fixed value for the variable name like &amp;quot;SERVER_NAME&amp;quot; (or whatever fails for you) in your ISAPI (and change no other code) - does that work or not. &lt;br&gt;&lt;br&gt;The ISAPI automatically sets up several standard HTTP variables when it &lt;br&gt;initializes, using fixed literal strings such as &amp;quot;PATH_INFO&amp;quot;, those strings work when I run the script</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#455506</link><pubDate>Wed, 24 Aug 2005 12:10:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:455506</guid><dc:creator>David Wang</dc:creator><description>Hmm... if it works with fixed literal string of &amp;quot;PATH_INFO&amp;quot; but fails with your null-terminated strings that are parsed, I have to say the problem still sits with your strings somehow. Are they CHAR, TCHAR, or WCHAR?&lt;br&gt;&lt;br&gt;You said the GetServerVariable() call fails with ERROR_INVALID_INDEX. And the same string, but as fixed literal string, works.&lt;br&gt;&lt;br&gt;Oh, and is this call made within ISAPI Extension or ISAPI Filter, and if ISAPI Filter, what filter event(s)?&lt;br&gt;&lt;br&gt;And you say that the string are null terminated, correct case, and no extraneous characters. So it should work but doesn't.&lt;br&gt;&lt;br&gt;Weird.&lt;br&gt;&lt;br&gt;Well, I'm sorry but I have no further suggestions. Your claims are mysterious but do not indicate any problems with IIS6.&lt;br&gt;&lt;br&gt;//David</description></item><item><title>HOWTO: Get Field Data for Custom Logging with ISAPI Filter</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#577032</link><pubDate>Sun, 16 Apr 2006 03:26:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:577032</guid><dc:creator>David Wang</dc:creator><description>Question:&lt;br&gt;I'm trying to write a Filter that handles writing a W3C-compliant log file based on a special...</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#609379</link><pubDate>Sun, 28 May 2006 18:53:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:609379</guid><dc:creator>dazhou</dc:creator><description>老王，这与编译配置有关。&lt;br&gt;&lt;br&gt;project property-&amp;gt; C++-&amp;gt;code generation-&amp;gt;basic runtime checks:&lt;br&gt;both &amp;nbsp; &amp;nbsp;(as debug) &amp;nbsp;can get ServerVariables.&lt;br&gt;&lt;br&gt;&lt;br&gt;project property-&amp;gt; C++-&amp;gt;code generation-&amp;gt;basic runtime checks:&lt;br&gt;both &amp;nbsp; &amp;nbsp;(as debug) &amp;nbsp;can get ServerVariables.&lt;br&gt;default &amp;nbsp;can't get ServerVariables.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#690766</link><pubDate>Mon, 07 Aug 2006 11:46:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:690766</guid><dc:creator>Murat</dc:creator><description>Louis - Do you use a second function to call GetServerVariable()?&lt;br&gt;&lt;br&gt;If you use the &amp;quot;ECB.GetServerVariable&amp;quot; directly in HttpExtensionProc there will be no problem! But if you use a function like GetMyVariable(ECB) in HttpExtensionProc and that function calls &amp;quot;GetServerVariable&amp;quot; using the parameter &amp;quot;ECB&amp;quot; it may fail!&lt;br&gt;&lt;br&gt;In GetMyVariable you have to define ECB as a variable parameter then it works. But if you define it as a value parameter it doesnt work.&lt;br&gt;</description></item><item><title>re: HOWTO: Use ISAPI GetServerVariable</title><link>http://blogs.msdn.com/david.wang/archive/2005/08/18/ISAPI-GetServerVariable.aspx#714925</link><pubDate>Wed, 23 Aug 2006 19:43:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:714925</guid><dc:creator>Bruno Marotta</dc:creator><description>Hi, &lt;br&gt;&lt;br&gt;is it possible to set an environment variable? I am trying to set the remote_addr to the x-forwarded-for http header with no success...</description></item></channel></rss>