dimanche 15 février 2015

Unable to read value from Web.Config

I'm trying to implement a recaptcha on a login page. But every time it hits the code , a null reference exception happens. I'm using asp.net with the default login template, it has its own Web.Config(not sure why though)


Is there a setting that needs to be done?Below are my codes.Hope to get a reply soon.


aspx file



<%@ Page Title="Log In" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"CodeBehind="Login.aspx.cs" Inherits="Penerangan.Emedia2u.Web.Account.Login" %>
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

<asp:Label Visible="false" ID="lblResult" runat="server" />
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" />


.cs file



recaptcha.PublicKey = System.Configuration.ConfigurationManager.AppSettings["reCAPTCHAPublicKey"].ToString();
recaptcha.PrivateKey = System.Configuration.ConfigurationManager.AppSettings["reCAPTCHAPrivateKey"].ToString();


web.config file



<appSettings>
<add key="reCAPTCHAPublicKey" value="fromgooglecaptchakey"/>
<add key="reCAPTCHAPrivateKey" value="fromgooglecaptchakey"/>
</appSettings>




Aucun commentaire:

Enregistrer un commentaire