类Validate继承了 System.Web.UI.Page但出现错误:Response is not available in this context.

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:42:26
部分代码:
namespace Validate
{
public class Validate : System.Web.UI.Page
{
private const double IMAGELENTHBASE = 12.5;
private const int IMAGEHEIGHT = 25;
private const int IMAGELINENUMBER = 25;
private const int IMAGEPOINTNUMBER = 100;
public static string VALIDATECODEKEY = "VALIDATECODEKEY";
private int length = 5;

public int Length
{
get { return length; }
set { length = value; }
}

public void CreateValidateImage(string code)
{
if (string.IsNullOrEmpty(code) == true) return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((code.Length * IMAGELENTHBASE)), IMAGEHEIGHT);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
Random random = new Random();

继承了也没错,你这是做自定义控件吗?那你还是别继承page了,换你要的服务器端控件来继承,然后在引入到你需要这个控件的网站里

别继承了,把当前的Response对象做为参数传进去算了

page还是需要继承的。
你把Response替换成HttpContext.Current.Response就可以了……
呵呵,我以前也遇到同样的问题……