エンコードされたすべてのリクエストをデコードするHTTPモジュールがあります。 これは、すべてのWCF要求に素晴らしい作品が、ませウェブのAPI requests-でWeb APIの要求を(両方のPOSTとGET)サービスになるには、まだ私はそれが再び、HTTPモジュールをヒットが、ことがわかりウェブAPIとHTTPモジュール
をエンコードそれでもコード化されたサービスに到達します。 どうすれば修正できますか?私は間違って何をしていますか? Web ApiのMessage Handlersで動作する方が良いとわかっていますが、HTTPモジュールはあまりにもうまく動作しないと思いますか?
HTTPモジュール:
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
context.EndRequest += context_PreSendRequestContent;
}
void context_PreSendRequestContent(object sender, EventArgs e)
{
string encodedQuerystring = HttpContext.Current.Request.QueryString.ToString();
if (!string.IsNullOrEmpty(encodedQuerystring))
{
System.Collections.Specialized.NameValueCollection col = new System.Collections.Specialized.NameValueCollection();
col.Add("q", encodedQuerystring);
WebFunction.CreateQuerystring(HttpContext.Current, col);
}
}
void context_BeginRequest(object sender, EventArgs e)
{
string encodedQueryString = String.Empty;
if (HttpContext.Current.Request.QueryString.Count > 0 && HttpContext.Current.Request.QueryString["q"] != null)
{
object _p = HttpContext.Current.Request.QueryString;
encodedQueryString = HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.QueryString["q"].ToString());
string originalQueryString = HttpContext.Current.Server.UrlDecode(WebFunction.Base64Decode(encodedQueryString));
if (!string.IsNullOrEmpty(originalQueryString))
{
WebFunction.CreateQuerystring(HttpContext.Current, WebFunction.ConvertQueryToCollection(originalQueryString));
}
}
}
WebFunction:
public static void CreateQuerystring(HttpContext context, System.Collections.Specialized.NameValueCollection nameValueCollection)
{
// reflect to readonly property
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(context.Request.QueryString, false, null);
context.Request.QueryString.Clear();
context.Request.QueryString.Add(nameValueCollection);
// make collection readonly again
isreadonly.SetValue(context.Request.QueryString, true, null);
}
Web APIを:
public class NamesController : ApiController
{
[HttpGet]
[ActionName("GET_NAMES")]
public Drugs_ResponseData Get(string q)
{
//need to add the decode function to get it to work
string[] arrAmpersant = Commonnn.DecodeFrom64(q).Split('&');
Names_obj = new Names();
return _obj.GetResult(Convert.ToInt32(Commonnn.GetValFromEqual(arrAmpersant[0])));
}
}
httpモジュールはどこに登録しましたか? ''内に登録した場合、アプリケーションプールは統合モードで実行する必要があります。 –
@KhanhTOはにあり、統合モードで実行されます。それはHTTPモジュールに到達しますが、依然としてリクエストにエンコードされます。 –
DasDas
リクエストごとにエンコードされたクエリ文字列が使用されている場所の数と、1時間にページにアクセスした訪問者の数を確認できますか? – LGSon