Cross Site Scripting & filter request asp.net
<p>i need to write a generic routine which will filter cross site scripting related character.
i found one that is in java. i dont know java. </p>

<h2>here is java code</h2>

<pre><code>package com.greatwebguy.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class CrossScriptingFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
}
public void destroy() {
    this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
    chain.doFilter(new RequestWrapper((HttpServletRequest) request), response);
}
</code></pre>

<p>}</p>

<pre><code>package com.greatwebguy.filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
public final class RequestWrapper extends HttpServletRequestWrapper {
public RequestWrapper(HttpServletRequest servletRequest) {
    super(servletRequest);
}
public String[] getParameterValues(String parameter) {
  String[] values = super.getParameterValues(parameter);
  if (values==null)  {
              return null;
      }
  int count = values.length;
  String[] encodedValues = new String[count];
  for (int i = 0; i &lt; count; i++) {
             encodedValues[i] = cleanXSS(values[i]);
   }
  return encodedValues;
}
public String getParameter(String parameter) {
      String value = super.getParameter(parameter);
      if (value == null) {
             return null;
              }
      return cleanXSS(value);
}
public String getHeader(String name) {
    String value = super.getHeader(name);
    if (value == null)
        return null;
    return cleanXSS(value);
}
private String cleanXSS(String value) {
            //You'll need to remove the spaces from the html entities below
    value = value.replaceAll("&lt;", "&amp; lt;").replaceAll("&gt;", "&amp; gt;");
    value = value.replaceAll("\\(", "&amp; #40;").replaceAll("\\)", "&amp; #41;");
    value = value.replaceAll("'", "&amp; #39;");
    value = value.replaceAll("eval\\((.*)\\)", "");
    value = value.replaceAll("[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']", "\"\"");
    value = value.replaceAll("script", "");
    return value;
}
</code></pre>

<p>}</p>

<pre><code>&lt;filter&gt;
&lt;filter-name&gt;XSS&lt;/filter-name&gt;
&lt;display-name&gt;XSS&lt;/display-name&gt;
&lt;description&gt;&lt;/description&gt;
&lt;filter-class&gt;com.greatwebguy.filter.CrossScriptingFilter&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter-mapping&gt;
&lt;filter-name&gt;XSS&lt;/filter-name&gt;
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
</code></pre>

<p>the url from where i got this code 
<a href="http://greatwebguy.com/programming/java/simple-cross-site-scripting-xss-servlet-filter/" rel="nofollow">http://greatwebguy.com/programming/java/simple-cross-site-scripting-xss-servlet-filter/</a></p>

<p>anyone can give me the tips to convert the code to asp.net &amp; c# or write class from scratch which mimic the above functionality.
thanks.</p>
