When calling webservice, I need to change the response text when calling a specific operation.
So I created an HttpModule that caught the answer and changed it.
Below code:
public class BeginEnd : IHttpModule { public void Init(HttpApplication context) { context.EndRequest += (o, e) => { HttpContext currContext = HttpContext.Current; NameValueCollection collection = currContext.Request.QueryString; if ( collection.Count > 0 && collection["op"] != null && collection["op"] == "ChangeService" ) { string xmlOther = "<root>My Test</root>"; currContext.Response.Clear(); currContext.Response.Write(xmlOther); currContext.Response.End(); } }; } public void Dispose() { } }
So, as you can see, I just cleared the Response object and placed my text.
Is this the right way to do this?
It works, but I think I'm missing something
What do you think?
source share