This file contains hidden or 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
public static List<string> NormalizeUrls(List<string> urls, string rootUrl) | |
{ | |
Uri uri; | |
if (!Uri.TryCreate(rootUrl, UriKind.Absolute, out uri)) return new List<string>(); | |
return urls.Select(url => !Uri.IsWellFormedUriString(url, UriKind.Absolute) ? string.Concat(uri.AbsoluteUri, url) : url).Distinct().ToList(); | |
} |
This file contains hidden or 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
public static List<string> ExtractUrls(string source) | |
{ | |
// match.Groups["name"].Value - URL Name | |
// match.Groups["url"].Value - URI | |
const string regexPattern = @"<a.*?href=[""'](?<url>.*?)[""'].*?>(?<name>.*?)</a>"; | |
var matches = Regex.Matches(source, regexPattern, RegexOptions.IgnoreCase); | |
return (from Match match in matches select match.Groups["url"].Value).ToList(); | |
} |
This file contains hidden or 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
public Image DownloadImage(string url) | |
{ | |
Image image = null; | |
try | |
{ | |
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); | |
httpWebRequest.AllowWriteStreamBuffering = true; | |
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201"; | |
httpWebRequest.Referer = "http://www.google.com/"; |
This file contains hidden or 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
public static string DownloadWebPage(string url) | |
{ | |
var webRequestObject = (HttpWebRequest)WebRequest.Create(url); | |
webRequestObject.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201"; | |
webRequestObject.Referer = "http://www.google.com"; | |
try | |
{ | |
var response = webRequestObject.GetResponse(); |
This file contains hidden or 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
using System.Text.RegularExpressions; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
namespace MobileTest | |
{ | |
/* | |
* Add the global filer RedirectMobileDevicesToMobileAreaAttribute to the global filter collection in | |
* the Application_Start() of Global.asax.cs file |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Permutation | |
{ | |
public static class Extension | |
{ | |
public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> source) | |
{ |
This file contains hidden or 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
protected void Application_AuthenticateRequest(Object sender, EventArgs e) | |
{ | |
if (HttpContext.Current.User == null) return; | |
if (!HttpContext.Current.User.Identity.IsAuthenticated) return; | |
var id = HttpContext.Current.User.Identity as FormsIdentity; | |
if (id == null) return; | |
FormsAuthenticationTicket ticket = id.Ticket; | |
string userData = ticket.UserData; | |
string[] roles = userData.Split(','); |
This file contains hidden or 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
<html> | |
<head> | |
<script type="text/javascript"> | |
var pageSize = 10; | |
var currentPageIndex = 0; | |
var pageCount = 0; | |
var startItemIndex = 0; | |
var itemsToDisplay = 0; |
This file contains hidden or 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
// First, install the reCaptcha library from Nuget https://nuget.org/packages/recaptcha. | |
// Then, create your public and private keys at http://www.google.com/recaptcha. | |
// 1. Create an extension method to genereate the Recaptcha javascript | |
public static class Extension | |
{ | |
public static MvcHtmlString GenerateCaptcha(this HtmlHelper htmlHelper) | |
{ | |
var html = Recaptcha.RecaptchaControlMvc.GenerateCaptcha(htmlHelper); | |
return MvcHtmlString.Create(html); |
NewerOlder