I am implementing captcha in one of my register form
In Example.Cs file I wrote the below :
public static class CaptchaHelper
{
public static string Captcha(this HtmlHelper helper, string text)
{
string srcPath = System.Web.VirtualPathUtility.ToAbsolute("~/Handler1.ashx");
string htmlContent = string.Empty;
htmlContent += "<script type=\"text/javascript\">function __rc(){document.getElementById(\"" + text +
"\").src = \"../Handler1.ashx?query=\" + Math.random();}</script>";
htmlContent += string.Format("<img id=\"{0}\" src=\"{1}\" alt=\"Captcha Image\"/>", text, srcPath);
htmlContent += "<a href=\"#\" onclick=\"javascript:__rc();\">Reset</a>";
return htmlContent;
}
}
And in View (.cshtml) I wrote the below :
@Html.Captcha("Sample")
In place of image its showing the script can any one help on this.
Thanks
Bhanu
Try this one…
Edit… Try this line…