Skip to content

Instantly share code, notes, and snippets.

@AaronLayton
Created March 4, 2014 17:38
Show Gist options
  • Save AaronLayton/9351598 to your computer and use it in GitHub Desktop.
Save AaronLayton/9351598 to your computer and use it in GitHub Desktop.
MVC Obfuscate emails
#### Helper
```csharp
@helper obfuscateEmail( string email , string text)
{
<a href="/contact/@email.Replace("@",":").Replace(".","+")">@text</a>
}
```
#### Usage
```html
Contact us by @obfuscateEmail("matt.juffs@his-house.com.uk","clicking here").
// Should produce
Contact us by <a href="/contact/matt+juffs:his-house+com+uk">clicking here</a>.
```
#### Controller
```csharp
[HttpGet]
public void ObfuscatedEmail( string email )
{
// Put the email back together
email = email.Replace(":","@").Replace("+",".");
Response.Redirect("mailto:" + email, true);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment