在c#的asp.net中catpcha [英] catpcha in asp.net in c#

查看:137
本文介绍了在c#的asp.net中catpcha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我只是想在我的asp.net页面上执行验证码。

但遗憾的是我收到了以下错误,

请帮我解决这个问题。

Hi all,
am just trying to do the captcha code in my asp.net page.
but unfortunately am getting the below error,
please help me solve this problem.

Compiler Error Message: CS0118: 'combination' is a 'variable' but is used like a 'method'

Source Error:

Line 99:             for (int i = 0; i <= 5; i++)
Line 100:            {
Line 101:              captcha.Append(combination(random.Next(combination.Length)));
Line 102:             // random.Next(combination.Length);
Line 103:  





我的代码是:



my code is:

private void FillCapctha()
{

    try
    {
        Random random = new Random();

        string combination = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        StringBuilder captcha = new StringBuilder();

        for (int i = 0; i <= 5; i++)
        {
          captcha.Append(combination(random.Next(combination.Length)));
         // random.Next(combination.Length);

        }

        Session["captcha"] = captcha.ToString();


        imgCaptcha.ImageUrl = "GenerateCaptcha.aspx?" + DateTime.Now.Ticks.ToString();


    }
    catch
    {
        throw;
    }

}







谢谢对所有人来说。




thanks to all.

推荐答案

Don;懒得自己酿造 - 它不太可能像正确的一样好,它会带你去需要付出很多努力。



相反,请查看使用 Recaptcha [ ^ ] - 免费,非常容易使用,美观和安全,它有助于世界数字化信息!
Don;t bother to "brew your own" - it's unlikely to be as good as the "proper" ones, and it'll take you a lot more effort.

Instead, look at using Recaptcha[^] - it's free, very easy to use, nice and secure, and it helps the world digitize information!


要回答你的问题,你希望得到指定字符串给定索引的字符,所以你需要方括号;



To answer your question you are looking to get the character at the given index of the comination string so you need square brackets for that;

for (int i = 0; i <= 5; i++)
{
    captcha.Append(combination[random.Next(combination.Length)]);
}





但是我同意滚动你自己是毫无意义的。如果你把它作为一个学习练习就好了,但如果你想真正使用它,你最好使用已经写过的。



However I agree that rolling your own is fairly pointless. It's fine if you're doing this as a learning exercise, but if you want to use it for real you are better using one already written.


因为你正在使用VB而发生错误-style圆括号从字符串返回一个字符。 C#使用方括号:

The error occurs because you're using VB-style round brackets to return a character from the string. C# uses square brackets:
captcha.Append(combination[random.Next(combination.Length)]);



try..catch 块中也没有任何意义,它只是重新抛出异常。



但是,正如格里夫所说,不要推出自己的CAPTCHA解决方案。现有的解决方案将更加安全,并且经过更好的测试。使用最新版本的reCAPTCHA,用户甚至不需要尝试读取一些扭曲的文本 - 他们只需要勾选一个框,这不那么烦人。


There's also no point in a try..catch block which simply re-throws the exception.

But, as Griff said, don't roll your own CAPTCHA solution. The existing solutions will be much more secure, and much better tested. With the latest version of reCAPTCHA, the user doesn't even need to try to read some distorted text - they just have to tick a box, which is much less annoying.


这篇关于在c#的asp.net中catpcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆