unicode 404 sinan 23rd September, 2006 19:26 (UTC)

Hi I don't know very well about ISAPI and I have a problem with ASP programming. When IIS executes 404, ??? appears instead of characters because IIS doesn't support Unicode. I want IIS to support Unicode and shows the proper character. As far as I understand, you refer to this problem. As I say, I am not very familiar with ISAPI.

I would appreciate very much if you could give me the full source code to accomplish this and how I install them. C++is installed to my computer and I can compile your sample codes. Thank you very much in advance.

Best regards

Sinan MERT

example http://torukomania.com/%E3%83%88%E3%83%AB%E3%82%B3/%E3%83%88%E3%83%AB%E3%82%B3

unicode 404 Kirit Sælensminde 25th September, 2006 04:46 (UTC)
sinan said

Hi I don't know very well about ISAPI and I have a problem with ASP programming. When IIS executes 404, ??? appears instead of characters because IIS doesn't support Unicode. I want IIS to support Unicode and shows the proper character. As far as I understand, you refer to this problem. As I say, I am not very familiar with ISAPI.

I would appreciate very much if you could give me the full source code to accomplish this and how I install them. C++is installed to my computer and I can compile your sample codes. Thank you very much in advance.

Best regards

Sinan MERT

example http://torukomania.com/%E3%83%88%E3%83%AB%E3%82%B3/%E3%83%88%E3%83%AB%E3%82%B3

Hmmm. You don't give too many details of your platform, but IIS does support Unicode, but in different ways and in different places. It's all a little more complex than it should be, but I'm not sure that it's all IIS's fault as the HTTP specs don't really talk about these issues at the protocol level.

The sequence in the URL looks like UTF-8 to me, but I haven't checked it — Firefox seems to interpret it though and to me it looks like Japanese. This is a good first step.

I think you've already read the discussion on David Wang's blog about these issues too. It looks like you won't be able to retrieve that character sequence from HTTP.SYS which drives the URL parsing for IIS and even worse the custom 404 handling mechanism further corrupts the URLs as I discuss in Errors in IIS's custom 404 error handling.

In practice though it is possible to get the URL in an ISAPI filter, but you will have to be running on Windows 2003 in order to do it. IIS 6 has support for the UNICODE_xxx server variables in some places, whilst earlier versions do not.

The documentation for the IIS filter isn't all it could be and the interface is poorly specified (it seems to me to have some const correctness issues), but the relevant part is GetServerVariable() on the filter data block.

When called with a NULL buffer this function returns the number of bytes required to hold the URL and not the number of characters. The relevant lines from the sample code are these:

    if ( 0 == filter.m_pfc->GetServerVariable( filter.m_pfc, const_cast< char * >( name.c_str() ), NULL, &len ) && len != 0 ) {
        boost::scoped_array< wchar_t > value( new wchar_t[ ++len / sizeof( wchar_t ) ] );
        if ( 0 == filter.m_pfc->GetServerVariable( filter.m_pfc, const_cast< char * >( name.c_str() ), value.get(), &len ) && len != 0 )

I'm afraid that I can't just give you some code that will work for you because I don't know which platform you are targetting; or what you data structure you expect the URL in; or what auxilliary libraries you use; or even what your error handling policies are. In the code above you need to know the following:

  • name is a std::string instance containing the server varialbe name, i.e. UNICODE_URL (note the const cast!)
  • boost::scoped_array is a smart pointer from the Boost library
  • len is a DWORD that contains the number of bytes required to fill in the array after the first call to GetServerVariable().

If both if statements succeed then you will have the URL in value.

The sample code I've given is a generic wrapper for the GetServerVariable() call which you will need to adapt to your environment.


I've moved the thread to the article on my site which I think is of most use for this (click on About on the thread at the top of the page) — I presume it is the one that you'd read (you added the thread to the forum page so I'm not 100% sure).


To join in the discussion you should register or log in