2008年8月31日

http://www.example.com/http://www2.example.com/ という値を Uri クラスのコンストラクタに渡すと http://www.example.com/http:/www2.example.com/ と二つ目以降のスラッシュの連続が一つにまとめられていたことがあって今は直っているのですが、 一体いつ起こって直ったんだろうと思ったので調べてみました。

それ困るの?と言われそうですが、例えばはてなブックマークのエントリのURLなどがそんな感じになってるので困るのです。というか困りました。困ってたのにいつの間にか直っていてアレ?っと思ったのです。

ちなみにUri class does not parse "http://.../http://..." properlyというフィードバックでなおしますよってことになっていて、報告がVisual Studio 2005なのでまあ順当に考えると2.0 SP1で直ると読めます。 一方、System.Uri constructor evaluates escaped slashes and removes double slashesではby design扱い。ひどい。先にこっち見てたから直らないものだとばかり。

ということで以下のようなコードで各バージョン試してみました。ついでに%2fを含められない話ももしかしたら途中で変わってるのかもと思って試してみました。

using System;
public class Program
{
 public static void Main(String[] args)
 {
  Console.WriteLine(Environment.Version);
  Console.WriteLine(new Uri("http://www.example.com/http://hauhau-users.jp/").AbsoluteUri);
  Console.WriteLine(new Uri("http://www.example.com/http://%2f%2fhauhau-users.jp/").AbsoluteUri);
 }
}

.NET Framework 1.0a。大丈夫っぽい。

C:\Documents and Settings\User\デスクトップ>test_v1.0.exe
1.0.3705.0
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http://%2f%2fhauhau-users.jp/

.NET Framework 1.1。コレも大丈夫っぽい。

C:\Documents and Settings\User\デスクトップ>test_v1.1.exe
1.1.4322.573
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http://%2f%2fhauhau-users.jp/

.NET Framework 2.0。やっぱりここでダメになった模様。

C:\Documents and Settings\User\デスクトップ>test_v2.0.exe
2.0.50727.42
http://www.example.com/http:/hauhau-users.jp/
http://www.example.com/http:/hauhau-users.jp/

.NET Framework 2.0 Service Pack 1。修正された。

C:\Documents and Settings\User\デスクトップ>test_v2.0.exe
2.0.50727.1433
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http:////hauhau-users.jp/

やっぱり.NET 2.0無印だけなのですね。.NET 1.xのSP適用版とかもやろうかと思ったけどめんどくさいのでパスで。

%2fが戻るやつのテストはうっかり戻ると連続になるようにしてしまったので.NET 2.0無印で消えてしまった…けど消えたと言うことは戻されてるのでやっぱり.NET 2.0から変わったっぽいですねー。dontEscape オプションをつけられなくなったのに…。

posted @ 20:10 | Feedback (0)
 

拡張子.ashxも.axdもASP.NETに割り当てられていて、IHttpHandlerを実装してhttpHandlersに登録すればどっちの拡張子でも同じように使えるのですね。

ふと、じゃあ.axd使ってもいいのかなと思ったわけです。でちょっと調べたらこんな感じのことが。

You should actually be able to use either extension -- both can be mapped to your own custom IHttpHandler.

If I had to pick one to use, I'd probably go with a .ashx extension. One reason for this is that there are no built-in .ashx end-points in ASP.NET -- whereas there are a few .axd ones (for example: the new webresources.axd). So going with a .ashx reduces the chance of a naming conflict.

.ashx files also now have intellisense support in VS 2005 -- so that makes building them easier as well.

まあどっちも使えるけど、ASP.NETに組み込まれているものに.ashxはないから(逆を言うと全部.axdだから)名前もかぶりにくくなるので.ashx使った方がいいよ、VS2005からはIntelliSense効くし。ということのよう。

posted @ 16:24 | Feedback (794)