<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
html {
height: 100%;
}
body {
height: 100%;
margin: 0px;
}
.container {
background-color: lightgray;
height: 100%;
}
.footer {
height: 50px;
background-color: gray;
margin-top: -50px;
}
</style>
</head>
<body>
<div class="container">
</div>
<div class="footer">
</div>
</body>
</html>
Friday, September 25, 2015
Simple CSS "Sticky Footer"
This method would probably need some tweaking to work in older browsers, but for my purposes, it works pretty good:
Thursday, September 24, 2015
Git push and pull
As I've explained in earlier posts, the command
is used to push changes to a remote repository. Similarly, the following command
pulls changes from the remote repository and merges these changes in with your local branch.
git push origin master
is used to push changes to a remote repository. Similarly, the following command
git pull origin master
pulls changes from the remote repository and merges these changes in with your local branch.
Tuesday, September 15, 2015
Implementing Forgot Password and Email Confirmation in ASP.NET Identity
This is one of those tasks that is not very difficult to actually accomplish but exceedingly difficult to find good instructions on how to do it. Forgot Password is simply a page where the user can enter his or her email address if he has forgotten his/her password. He/she then receives an email containing a link where the password can be reset. Email Confirmation means that when a user first registers, he/she cannot log in until the email is confirmed. How is the email confirmed? The person is sent an email containing a link to click that will mark the address as confirmed. This all sounds complicated, but ASP.NET Identity builds all of this for you when you create an ASP.NET web application with Individual Accounts. However, the code in the AccountController is commented out initially. Because email is a central part of these operations, you must first configure your email.
To configure your email, just open up the IdentityConfig.vb file. Find the EmailService class and add code to the SendAsync method. The code below illustrates some code that sends an email using a traditional SMTP server:
Once this is configured, go back to your AccountController and uncomment out the appropriate lines.
To configure your email, just open up the IdentityConfig.vb file. Find the EmailService class and add code to the SendAsync method. The code below illustrates some code that sends an email using a traditional SMTP server:
Public Class EmailService Implements IIdentityMessageService Public Function SendAsync(message As IdentityMessage) As Task Implements IIdentityMessageService.SendAsync ' Plug in your email service here to send an email. Dim SmtpServer As String If System.Configuration.ConfigurationManager.AppSettings("SmtpServer") Is Nothing Then Throw New Exception("The SmtpServer key is not present in the web.config file.") Else SmtpServer = System.Configuration.ConfigurationManager.AppSettings("SmtpServer") End If Dim FromAddress As String If System.Configuration.ConfigurationManager.AppSettings("ConfirmationEmailFrom") Is Nothing Then Throw New Exception("The ConfirmationEmailFrom key is not present in the web.config file.") Else FromAddress = System.Configuration.ConfigurationManager.AppSettings("ConfirmationEmailFrom") End If Dim MyClient As New System.Net.Mail.SmtpClient(SmtpServer) Dim MyMessage As New System.Net.Mail.MailMessage MyMessage.From = New Net.Mail.MailAddress(FromAddress) MyMessage.Subject = message.Subject MyMessage.Body = message.Body MyMessage.IsBodyHtml = True MyMessage.To.Add(message.Destination) MyClient.Send(MyMessage) Return Task.FromResult(0) End Function End Class
Once this is configured, go back to your AccountController and uncomment out the appropriate lines.
reCAPTCHA 2.0
The folks at Google have released a new version of their CAPTCHA product named reCAPTCHA. They refer to the new version as the No CAPTCHA reCAPTCHA. It's fairly easy to implement even in an ASP.NET MVC web application as I'll show below.
First, go here and sign up. You input the domains at which your site will be hosted. LocalHost always "just works" so don't worry about development. However, if you're testing at a different domain than production, be sure to put both in there. You'll be given two keys. The "site" key and the "secret" key.
Implementing the CAPTCHA is a two part process.
First Part - Display the CAPTCHA control for the user to "solve"
Add this to the top of your view:
Then add this where you want the CAPTCHA box to appear:
That's all.
Second Part - Verify that the CAPTCHA was solved correctly
This is the more tricky of the two parts.
Once the user submits the form, reCAPTCHA is going to insert an additional form field named g-recaptcha-response into the form. This will look like gobbly-gook. This response along with the secret key needs to be sent to a Google web service. The web service will return a JSON object that contains a success attribute. If the success attribute is true, the user solved the CAPTCHA and you can safely assume that he or she is not a bot.
First, in your controller, add a data contract that you can deserialize the JSON response into:
Next, in your post action method within the controller use the following code:
First, go here and sign up. You input the domains at which your site will be hosted. LocalHost always "just works" so don't worry about development. However, if you're testing at a different domain than production, be sure to put both in there. You'll be given two keys. The "site" key and the "secret" key.
Implementing the CAPTCHA is a two part process.
First Part - Display the CAPTCHA control for the user to "solve"
Add this to the top of your view:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Then add this where you want the CAPTCHA box to appear:
<div class="g-recaptcha" data-sitekey="SITE-KEY-GOES-HERE" ></div>
That's all.
Second Part - Verify that the CAPTCHA was solved correctly
This is the more tricky of the two parts.
Once the user submits the form, reCAPTCHA is going to insert an additional form field named g-recaptcha-response into the form. This will look like gobbly-gook. This response along with the secret key needs to be sent to a Google web service. The web service will return a JSON object that contains a success attribute. If the success attribute is true, the user solved the CAPTCHA and you can safely assume that he or she is not a bot.
First, in your controller, add a data contract that you can deserialize the JSON response into:
<System.Runtime.Serialization.DataContract> Private Class GoogleResults <System.Runtime.Serialization.DataMember(Name:="success")> Public Success As Boolean End Class
Next, in your post action method within the controller use the following code:
Dim RecaptchaResponse As String = Request("g-recaptcha-response") Dim MyClient As System.Net.WebClient = New System.Net.WebClient Dim Reply As String = _ MyClient.DownloadString(String.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", "SECRET-KEY-GOES-HERE", RecaptchaResponse)) Dim MySerializer As New System.Runtime.Serialization.Json.DataContractJsonSerializer(GetType(GoogleResults)) Dim MyStream = New System.IO.MemoryStream(Encoding.Unicode.GetBytes(Reply)) Dim Results As GoogleResults = CType(MySerializer.ReadObject(MyStream), GoogleResults) If Not Results.Success Then ModelState.AddModelError("", "You must verify that you are not a robot.") End If If Not ModelState.IsValid Then Return View(model) End If
Subscribe to:
Posts (Atom)