HttpWebRequest keeps timing out

It has already happened to me a couple of times and every time I forget what the issue was and how to solve it. That’s why I decided to write a short post about it, so hopefully next time I will remember. 🙂 The problem arises when making a few (independent) HTTP requests using C#’s

. At first it sounds like a very usual thing to do, but the mystical part of it is that the first few requests succeed and then at a certain point the others start timing out. You may be tempted to increase the

first, but you will soon understand that it does not solve the problem. Continue Reading…

ASP.NET localization with Umbraco

Umbraco is very neat and easy to integrate with ASP.NET, probably because it was built on it. One typical scenario is to create a multi-lingual web site with Umbraco, which automatically requires the use of localization. Umbraco supports localization very well and there are two main techniques, I can think of – using a dictionary or using a special page with custom fields. I personally prefer the latter, because one can use nicer names and descriptions for the custom fields, so it is easier and more intuitive to edit the texts.

Umbraco Localization Structure It is a good idea to create a separate branch in Umbraco for each language in your website. You should keep the language-independent settings in the root node and all language-dependent ones in the branches.

The next step is to use this localization in your custom controls in ASP.NET. Umbraco has a nice control, called item, which can display the contents of a property. By default, this control tried to look up the property in the current node, however you can also specify a node by its id. So, one solution is to use this control and specify the node ID of your Texts node every time (or create some wrapper over this control). However, I find this way very clumsy in spite of the nice properties the item control provides. Continue Reading…

Why is ASP.NET MVC so Popular?

Classic ASP.NET

ASP.NET MVC has become more and more popular. Why? The ordinary ASP.NET allows developers to abstract from many details like request/response headers (by wrapping everything in nice API), manual HTML coding (by using server-side controls), etc. Everything is really cool – we develop a Web site for seconds. But what about the maintainability of this site later? Customers always want more and more. Even after years they may ask you to implement a new feature for them. And then developers start to sink into the depth of their own code ocean. If we add the lack of good documentation, the entire situation becomes really bad. Continue Reading…

Capture the HTML output from a custom server control in ASP.NET

Custom server controls do great job. A complex page can easily be split into many controls. In this way it becomes easier to support after that. Used in a page, a server control follows the whole page life cycle.

Sometimes you will need just to get the HTML output from a server control for a different usage like sending it by an e-mail. So what can you do?  There is a method called RenderControl, which renders a control using a HtmlTextWriter object. We can simply load the control using the LoadControl method and then use RenderControl.

But the output is not what we really want. It contains only the static HTML tags. The server controls inside our control are not rendered. Why? Because in our way, the control does not follow the page life cycle. So, what we should do is to add it to a page.

Server.Execute method executes an IHttpHandler object and writes the output using a TextWriter object. In this way we follow the whole page life cycle so our control will render everything inside it.