If you are using code-behind to create a HttpWebRequest like var request = (HttpWebRequest)WebRequest.Create(Url); and then trying to use that request to get the WebResponse like var response = (HttpWebResponse)request.GetResponse(); This will error out as following “HttpWebRequest The underlying connection was closed: An unexpected error occurred on a send” To fix that you have to…
Tag: C#
Want a cookie for you or foreach of you?
Ran into a weird cookie issue HttpWebRequest cookies are disabled for security by default. You need to enable it. Now if you want to add cookies from your current request, since they are seperate types, you have add it manually. Example my httpCookies – HttpContext.Current.Request.Cookies; var request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); //now your…
Simple way to Flip a string
I just thought sometimes simple extensions helps a lot. Like this Flip. public static string Flip(this string target, bool trimEnds) { if (trimEnds) target= target.TrimIfNotNull(); var len = target.Length; var newString = new string[len]; foreach (var c in target) { var temp = len; newString[temp – 1] = c.ToString(); len–; } return string.Join(string.Empty, newString); }…
Leveraging Scaffolders to Implement Repository pattern for your project
I have shown in last couple of posts how to use 1. MVCScaffolding to scaffold your MVC 4 project with Razor View Engine, 2. Use the Migration tool to use code first approach. I still want to show you how to use the repository pattern using the Scaffolding technique Here is the outline…