验证码不能用于表单身份验证吗?

时间:2014-03-18 10:09:49

标签: asp.net authentication web-config captcha

伙计们我想在asp.net网站上使用MSCaptcha。它工作正常,但只要我在web.config中添加Forms身份验证,就不会显示验证码图像。

认证前的Web.config(显示Captcha图像)

<system.web>
<httpRuntime targetFramework="4.5" />
<authorization>
  <allow users="*" />
</authorization>

 <httpHandlers>
  <add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.captchaImageHandler, MSCaptcha" />
</httpHandlers>
 </system.web>

<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />

  <handlers>
  <add name="MSCaptcha.captchaImageHandler" verb="GET" path="CaptchaImage.axd" type="MSCaptcha.captchaImageHandler, MSCaptcha" resourceType="Unspecified" />
</handlers>     

添加表单身份验证后的Web.Config(Captcha图像未加载)

<system.web>
<httpRuntime targetFramework="4.5" />
<authorization>
  <deny users="?" />
  <allow users="*" />
  <allow users="GET" />
</authorization>

 <authentication mode="Forms">
  <forms name=".ASPXFORMSDEMO" loginUrl="Default2.aspx"
  protection="All" path="/" timeout="30" />
</authentication>

 <httpHandlers>
  <add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.captchaImageHandler, MSCaptcha" />
</httpHandlers>
 </system.web>

<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />

  <handlers>
  <add name="MSCaptcha.captchaImageHandler" verb="GET" path="CaptchaImage.axd" type="MSCaptcha.captchaImageHandler, MSCaptcha" resourceType="Unspecified" />
</handlers>

为什么表单身份验证会导致验证码出现问题?我该怎么办?

P.S这个web-config文件不完整所以看起来很混乱。

1 个答案:

答案 0 :(得分:1)

您需要在web.config中添加LOCATION

<location path="CaptchaImage.axd">
 <system.web>
<authorization>
  <allow users="*">
  </allow>
</authorization>
</system.web>
</location>