Created
March 4, 2014 17:38
-
-
Save AaronLayton/9351598 to your computer and use it in GitHub Desktop.
MVC Obfuscate emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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