0

I've inherited a pre-compiled website that uses javascript created in a generic handler (ashx). I need to modify the js, but I dont have the source, only the pre-compiled libraries. Currently, we're simply doing an http request on the ashx, modifying the result and then outputting it directly on the site:

<script runat="server">
    protected string getJs()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(Request.Url, "/js.ashx"));
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader sr = new StreamReader(response.GetResponseStream());
        return = sr.ReadToEnd().Replace("old stuff", "new stuff");
    }
</script>

<script type="text/javascript">
    <%= getJs() %>
</script>

This seems like a pretty round-about way of doing this. Is there anyway to modify the output of a generic handler without requesting the page itself?

Adam
  • 1,984
  • 2
  • 16
  • 19

1 Answers1

2

You can try dis-assembling the pre-compiled piece, if you have access to the actual dll. See converting-il-to-c-code and similar SO questions.

Using .NET Reflector you may have a workable (C#) version of the code behind js.ashx. This source can (hopefully) be slightly modified to be directly callable, or better, to produce the desired Javascript.

Community
  • 1
  • 1
gimel
  • 83,368
  • 10
  • 76
  • 104