Click here to Skip to main content
16,011,608 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: .NET Server RC1: Weird Pin
Paul Watson20-Oct-02 5:41
sitebuilderPaul Watson20-Oct-02 5:41 
GeneralRe: .NET Server RC1: Weird Pin
leppie20-Oct-02 6:06
leppie20-Oct-02 6:06 
GeneralEscaping nasty HTML tags... Pin
Ray Cassick17-Oct-02 18:50
Ray Cassick17-Oct-02 18:50 
GeneralRe: Escaping nasty HTML tags... Pin
Paul Riley18-Oct-02 0:20
Paul Riley18-Oct-02 0:20 
GeneralRe: Escaping nasty HTML tags... Pin
Daniel Turini18-Oct-02 6:11
Daniel Turini18-Oct-02 6:11 
GeneralRe: Escaping nasty HTML tags... Pin
Paul Watson18-Oct-02 7:29
sitebuilderPaul Watson18-Oct-02 7:29 
GeneralRe: Escaping nasty HTML tags... Pin
Ray Cassick20-Oct-02 8:24
Ray Cassick20-Oct-02 8:24 
GeneralRe: Escaping nasty HTML tags... Pin
Richard Deeming21-Oct-02 2:08
mveRichard Deeming21-Oct-02 2:08 
Regular expressions is the way to go. You need to escape all script, object, applet, embed and param tags, and remove any event handlers on other tags.
using System.Text.RegularExpressions;
...
static bool IsLikeRe(string src, string pattern) 
{
    return Regex.IsMatch(src, pattern, 
        RegexOptions.IgnoreCase | RegexOptions.Singleline);
}
 
static string ReReplace(string src, string pattern, string replace) 
{
    return Regex.Replace(src, pattern, replace,
        RegexOptions.IgnoreCase | RegexOptions.Singleline);
}
 
static string ReReplaceAll(string src, string pattern, string replace)
{
    string ret = src;
    while (IsLikeRe(ret, pattern))
        ret = ReReplace(ret, pattern, replace);
 
    return ret;
}
 
static string StripScript(string html)
{
    // Strip <script...> tags
    string res = ReReplaceAll(html, "<script(.*)>", "&lt;script$1&gt;");
    // Strip </script...> tags
    res = ReReplaceAll(res, "</script(.*?)>", "&lt;/script$1&gt;");
 
    // Strip object tags
    res = ReReplaceAll(res, "<(object|applet|embed|param)([^>]*)>", 
        "&lt;$1$2&gt;");
    res = ReReplaceAll(res, "</(object|applet|embed|param)([^>]*)>", 
        "&lt;$1$2&gt;");
 
    // Strip event handlers from tags
    res = ReReplaceAll(res,
        @"<([^>]+?)\son(?:[^>]+?)=(['""])(?:[^>]+?)\2([^>]*?)>",
        "<$1$3>");
 
    return res;
}

GeneralTwo lines want to others' help. Pin
zhoujun17-Oct-02 15:03
zhoujun17-Oct-02 15:03 
GeneralHome page configuring Pin
Sarvesvara (BVKS) Dasa17-Oct-02 8:47
Sarvesvara (BVKS) Dasa17-Oct-02 8:47 
Questionvb6 webclass equivalent (or better) in asp.net ? Pin
ryancrawcour17-Oct-02 1:45
ryancrawcour17-Oct-02 1:45 
AnswerRe: vb6 webclass equivalent (or better) in asp.net ? Pin
Paul Watson17-Oct-02 22:00
sitebuilderPaul Watson17-Oct-02 22:00 
GeneralRe: vb6 webclass equivalent (or better) in asp.net ? Pin
ryancrawcour18-Oct-02 5:09
ryancrawcour18-Oct-02 5:09 
GeneralRe: vb6 webclass equivalent (or better) in asp.net ? Pin
Paul Watson18-Oct-02 8:22
sitebuilderPaul Watson18-Oct-02 8:22 
GeneralUser Control and Datalist Pin
Mazdak16-Oct-02 22:19
Mazdak16-Oct-02 22:19 
GeneralMeeting trouble when using JSP to connect DB2 Pin
George216-Oct-02 17:02
George216-Oct-02 17:02 
GeneralA custom control and an click event Pin
Paul Watson16-Oct-02 1:38
sitebuilderPaul Watson16-Oct-02 1:38 
GeneralRe: A custom control and an click event Pin
Paul Riley16-Oct-02 2:10
Paul Riley16-Oct-02 2:10 
GeneralRe: A custom control and an click event Pin
Paul Watson16-Oct-02 2:27
sitebuilderPaul Watson16-Oct-02 2:27 
GeneralRe: A custom control and an click event Pin
Paul Riley16-Oct-02 2:33
Paul Riley16-Oct-02 2:33 
GeneralRe: A custom control and an click event Pin
Paul Watson16-Oct-02 2:59
sitebuilderPaul Watson16-Oct-02 2:59 
GeneralIIS and SSL Pin
Shaun Wilde15-Oct-02 23:21
Shaun Wilde15-Oct-02 23:21 
GeneralRe: IIS and SSL Pin
Megan Forbes16-Oct-02 0:50
Megan Forbes16-Oct-02 0:50 
GeneralRe: IIS and SSL Pin
Shaun Wilde16-Oct-02 1:13
Shaun Wilde16-Oct-02 1:13 
GeneralRe: IIS and SSL Pin
Megan Forbes16-Oct-02 1:40
Megan Forbes16-Oct-02 1:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.