添加新的类文件,为什么不能使用Response函数?

rijcm 2004-12-28 11:40:30
这类文件是Kaersoft_Forum里的一个HTML标签处理文件 现在我想加上过滤SQL的关健字。如果发现有则自动 Response.Redirect("error.aspx") 转向。现在的问题是我在这文件根本没办法使用Response.Redirect("error.aspx") 。该有的命名空间我都用上了 可还是不行:(

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text.RegularExpressions;

namespace uclub
{
/// <summary>
/// 转换用户的输入。
/// </summary>
public sealed class ConvertString
{

/// <summary>
/// 将用户输入的字符串转换为可换行、替换Html编码、无危害数据库特殊字符、去掉首尾空白、的安全方便代码。
/// </summary>
/// <param name="inputString">用户输入字符串</param>
public static string ConvertStr(string inputString)
{
string retVal=inputString;
retVal=retVal.Replace("&","&");
retVal=retVal.Replace("\"",""");
retVal=retVal.Replace("<","<");
retVal=retVal.Replace(">",">");
retVal=retVal.Replace(" "," ");
retVal=retVal.Replace(" ","  ");
retVal=retVal.Replace("\t","  ");
retVal=retVal.Replace("\r", "<br>");
return retVal;
}

public static string OutputText(string inputString)
{
string retVal=inputString;
retVal= ConvertStr(retVal);
retVal=retVal.Replace(" retVal=retVal.Replace("" target="_blank">", "");
retVal=retVal.Replace("
", "");
retVal=retVal.Replace("[img]", "");
retVal=retVal.Replace("[/img]", "");
retVal= Regex.Replace(retVal,@"\[flash=\d+,\d+](?<x>[^\]]*)\[/flash]",@"$1",RegexOptions.IgnoreCase);
retVal=retVal.Replace("[flash]", "");
retVal=retVal.Replace("[/flash]", "");
return retVal;
}

//过滤SQL关键,防止SQL远程注入攻击
public static string FilterSql(string inputString)
{
string retVal=inputString;
if (retVal==null)
{
retVal="0";
}
string strFilter="',;,//,--,@,_,exec,declare,create";
string[] x=Regex.Split(strFilter,",");
for (int i=1;i<x.Length;i++)
{
if(retVal.ToString().IndexOf(x[i].ToString())>-1)
{
retVal="jf_error";
break;
}
}
return retVal;
}

public static string ToUrl(string inputString)
{
string retVal=inputString;
retVal= ConvertStr(retVal);
retVal= Regex.Replace(retVal,@"\(?<x>[^\]]*)\",@"<a href=""$1"" target=""_blank"">$1</a>",RegexOptions.IgnoreCase);
retVal= Regex.Replace(retVal,@"\[flash=(?<width>\d+),(?<height>\d+)](?<x>[^\]]*)\[/flash]",@"<embed src=""$3"" width=""${width}"" height=""${height}""></embed>",RegexOptions.IgnoreCase);
retVal= Regex.Replace(retVal,@"\[flash](?<x>[^\]]*)\[/flash]",@"<embed src=""$1""></embed>",RegexOptions.IgnoreCase);
return Regex.Replace(retVal,@"\[img](?<x>[^\]]*)\[/img]",@"<a href=""$1"" target=""_blank""><img src=""$1"" onload=""javascript:if(this.width>screen.width-220)this.width=screen.width-220"" border=1></a>",RegexOptions.IgnoreCase);
}
}
}
...全文
95 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxboy 2004-12-28
  • 打赏
  • 举报
回复
类文件不是aspx页面,不能直接输出的,他的默认缺少相应的引用。 二楼回复有效
rijcm 2004-12-28
  • 打赏
  • 举报
回复
TO:ccwq([Kiss Eash Not Teach])

HttpContext.Current.Response.Redirect("error.aspx");

使用这办法已经可以了,能说明为什么要使用HttpContext.Current 这个吗?
ccwq 2004-12-28
  • 打赏
  • 举报
回复
或者你可以把出错的信息做一个变量,回传给调用此类的进程,让进程去处理重定向
ccwq 2004-12-28
  • 打赏
  • 举报
回复
HttpContext.Current.Response.Redirect("error.aspx");
rijcm 2004-12-28
  • 打赏
  • 举报
回复
现在我的做法是返回一个特定的字符,对比字符为jf_error则再转向。。。

//过滤SQL关键,防止SQL远程注入攻击
public static string FilterSql(string inputString)
{
string retVal=inputString;
if (retVal==null)
{
retVal="0";
}
string strFilter="',;,//,--,@,_,exec,declare,create";
string[] x=Regex.Split(strFilter,",");
for (int i=1;i<x.Length;i++)
{
if(retVal.ToString().IndexOf(x[i].ToString())>-1)
{
retVal="jf_error";// 这是我目前的做法
Response.Redirect("error.aspx");//我这样想写程序运行出错。
break;
}
}
return retVal;
}

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧