どうすれば“スムーズに” HttpHandler URIをフォーマットしますか?
-
02-07-2019 - |
質問
ASP.Net 2.0を使用してC#のRESTful Webサービスの方法を調整し、(クラスライブラリ、前者によって生成されたdllへの参照、およびweb.configの調整を介して)次のようなURI形式を同軸化します。
http:// localhost / DevelopmentProject / testhandler /?input = thisismyinput
これは、入力を啓発的な接頭辞" Your Input Was:"
の付いたテキストとして単純に返します。私は、URIを次の行に沿ってさらに平滑化できるという印象を受けました:
http:// localhost / DevelopmentProject / testhandler / thisismyinput
同じ結果になりますが、厄介な"?input ="を取り除く方法がわかりません
web.configのhttphandlersセクションへのエントリは次のとおりです(コードが表示されるようにスペースが追加されています):
<追加verb =" *" path =" testhandler / *" type =" HandlerLib.testhandler、HandlerLib" />
ローカルマシンでIIS 5.1を実行していますが、これにより問題が発生しますか?
本質的にどこが間違っているのですか?
ありがとう。
解決 3
他のヒント
1つの解決策は、UrlRewritingを使用してUrlを必要なものに書き換えることです。
http://urlrewriter.net/ を使用してすべての書き換えを行い、次のような設定を行うことができます。あなたのシナリオでこれ
<rewriter>
<rewrite
url="DevelopmentProject/testhandler/([\w]+)"
to="DevelopmentProject/testhandler/?input=$1" />
</rewriter>
これは&quot; http:// localhost / DevelopmentProject / testhandler / thisismyinput&quot;のままです。ブラウザのアドレスバーで、&quot; http:// localhost / DevelopmentProject / testhandler /?input = thisismyinput&quot;
として処理します。URLRewriter.net などを使用して、URL書き換えを実装できます。 これにより、前述の構文を使用できます。
設定を次から変更します。 &lt;追加verb =&quot;&quot; path =&quot; testhandler /&quot; type =&quot; HandlerLib.testhandler、HandlerLib&quot; /&gt; に: &lt;追加verb =&quot;&quot; path =&quot; testhandler / *&quot; type =&quot; HandlerLib.testhandler、HandlerLib&quot; /&gt;
ハンドラーのProcessRequest関数でRequest.PathInfoの値をチェックアウトします http:// localhost / DevelopmentProject / testhandler / thisismyinput のようなURLを使用します。
それができない場合は、IIS 5.1がすべての要求をaspnet_isapi.dllにルーティングしていることを確認してください。 (とはいえ、すでに存在しているようです)これは「構成...」ですボタン&gt; &quot;アプリマッピング&quot; IISの仮想ディレクトリのタブ。