저는 ASP.NET을 처음 사용했습니다. 내가/BuildCaptcha.aspx 보안 문자에 다음 코드 한 http://www.codekicks.com/2008/04/implement-simple-captcha-in-cnet.html.NET 1.1 보안 문자 구현 컴파일러 오류
:
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Color" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script language="C#" runat="server">
Bitmap objBMP = new Bitmap(60, 20);
Graphics objGraphics = Graphics.FromImage(objBMP);
objGraphics.Clear(Color.Wheat);
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
//' Configure font to use for text
Font objFont = new Font("Arial", 8, FontStyle.Italic);
string randomStr = "";
char[] myArray = new char[5];
int x;
//That is to create the random # and add it to our string
Random autoRand = new Random();
for (x = 0; x < 5; x++)
{
myArray[x] = System.Convert.ToChar(autoRand.Next(65,90));
randomStr += (myArray[x].ToString());
}
//This is to add the string to session, to be compared later
Session.Add("RandomStr", randomStr);
//' Write out the text
objGraphics.DrawString(randomStr, objFont, Brushes.Red, 3, 3);
//' Set the content type and return the image
Response.ContentType = "image/GIF";
objBMP.Save(Response.OutputStream, ImageFormat.Gif);
objFont.Dispose();
objGraphics.Dispose();
objBMP.Dispose();
</script>
나는 다음과 같은 오류가 발생하고 클라이언트의 서버는 .NET 1.1을 실행하고 나는 여기에 설명 된 간단한 보안 문자를 구현하기 위해 노력하고 captcha 방문시/BuildCaptcha.aspx :
Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration
Source Error:
Line 7: Bitmap objBMP = new Bitmap(60, 20);
Line 8: Graphics objGraphics = Graphics.FromImage(objBMP);
Line 9: objGraphics.Clear(Color.Wheat);
Line 10: objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
Line 11: //' Configure font to use for text
Source File: \\...\captcha\BuildCaptcha.aspx Line: 9
귀하의 도움에 감사드립니다.
최저
, 마크
(나는 명백한 비의 C# -1.2 코드를 볼 수없는 오류에 대해 언급 할 수 없습니다),하지만 : a). NET 1.1은 공식적으로 쓸모 없으며, b)'System.Drawing'은 웹 서버에서 지원되지 않습니다. 그리고 c)'using' 문 (객체의 수명에 걸친)은'에 비해 훨씬 낫습니다. Dispose()' –
감사합니다. Marc. Web.Config 파일을 수정하지 않고 .NET 2.0에서 위의 코드를 수정하는 방법이 있습니까? 다른 사용 가능한 솔루션과 같이를 추가하려고하면 서버의 구성이 잘못됨을 발견했습니다. 따라서 이미지를 동적으로 생성하는 페이지가 바람직합니다. –
garromark