登録フォームの 1 つにキャプチャを実装しています
Example.Cs ファイルでは、以下を記述しました。
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;
}
}
そしてビュー(.cshtml)で私は以下を書きました:
@Html.Captcha("Sample")
画像の代わりにスクリプトを表示すると、誰でもこれに役立ちます。
ありがとうバヌ