Friday, April 5, 2013
MVC 4: facebook twitter login with oAuth
http://www.dotnetexpertguide.com/2012/08/facebook-twitter-oauth-openid-login-with-aspnet-mvc-4-application.html
Wednesday, April 3, 2013
How to set Connection: Keep-Alive in C# HttpWebRequest class ?
Cannot set by: webrequest.KeepAlive = true;
Have to set this request header by reflection
Reference:
http://stackoverflow.com/questions/7458556/c-sharp-connection-keep-alive-header-is-not-being-sent-during-httpwebrequest
Have to set this request header by reflection
var req = (HttpWebRequest)WebRequest.Create(someUrl);
var sp = req.ServicePoint;
var prop = sp.GetType().GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic);
prop.SetValue(sp, (byte)0, null);Reference:
http://stackoverflow.com/questions/7458556/c-sharp-connection-keep-alive-header-is-not-being-sent-during-httpwebrequest
Tuesday, April 2, 2013
How to validate a URL in ASP.NET?
By Regular expression data annotation in Model class
[RegularExpression(@"^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", ErrorMessage = "Invalid url")]
public string Url { get; set; }
[RegularExpression(@"^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", ErrorMessage = "Invalid url")]
public string Url { get; set; }
How to set Max length for an input in ASP.NET MVC
By StringLength data annotation
[StringLength(20, ErrorMessage = "Name cannot be longer than 20 characters.")]
public string Name { get; set; }
[StringLength(20, ErrorMessage = "Name cannot be longer than 20 characters.")]
public string Name { get; set; }
Monday, April 1, 2013
How to use TextArea for @Html.EditorFor in ASP.NET MVC?
Two ways:
1. Add data annotation in Model class
[DataType(DataType.MultilineText)]
public string Text { get; set; }
2. @Html.TextAreaFor(model => model.Text)
1. Add data annotation in Model class
[DataType(DataType.MultilineText)]
public string Text { get; set; }
2. @Html.TextAreaFor(model => model.Text)
Subscribe to:
Posts (Atom)