Branislav Abadjimarinov's technical blog

Branislav Abadjimarinov's technical blog - For October 2009

  1. Course Programming .NET and WPF

    This semester at FMI, Sofia University, is starting a new course dedicated to programming  .NET and using the latest Microsoft  technologies. The course is called "Programming .NET and WPF".  You can check out the program of the course on the official site of FMI. The course also has an online home - www.dotnet.graduate-bg.com , where you can check the schedule of the lectures, download the presentations or ask questions in the forum . The course will present the newest and most powerful presentation technology from Microsoft - WPF (Windows Presentation Foundation). I'll do some basic lectures on Attributes and Strings and also some more in depth presentation on LINQ and multi-threaded programming techniques. This course continues the fine tradition not only to show the latest technologies but also to give students a chance to play and develop their own projects as part of the curriculum.

    Posted by Branislav Abadjimarinov on October 28 at 2:53 PM

  2. How to render asp.net control to string

    Every control in ASP.NET inherits from System.Web.UI.Control and have the RenderControl method. When you want to get the html output of the control at any point of the page execution lifecycle you can use the following method.

    public string RenderControl(Control ctrl)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter tw = new StringWriter(sb);
        HtmlTextWriter hw = new HtmlTextWriter(tw);

        ctrl.RenderControl(hw);
        return sb.ToString();
    }

    At this point ASP.NET MVC does not have full support for asp.net controls. Using this trick you can render control's html directly on the view using a html helper. While this is good for read-only controls it will not work with controls that require event handling because in ASP.NET MVC by default you are missing  the page lifecycle.

    Posted by Branislav Abadjimarinov on October 28 at 9:10 AM

  3. ASP.NET MVC default route problem

    If you are working with ASP.NET MVC you definitely have seen that in the startup project in Visual Studio in Global.asax file there is a default route added like this:

    routes.MapRoute(
    "Content",     // Route name
    "{controller}/{action}/{id}",    // URL with parameters
    new { controller = "Home", action = "Index", id = "" } // Parameter defaults
    );

    It is very useful to quickly show how the MVC works but in commercial projects I'll suggest  not to use a default route for handling /{Controller}/{Action} requests in ASP.NET MVC. By doing that you can get a ton of these exceptions:

    System.Web.HttpException: The controller for path '/MyCustomPath/' could not be found or it does not implement IController.

    The reason for this is that when you make a request for non-existing path like /MyCustomPath/ the MVC Controller factory will try to instantiate a class inheriting IController and named "MyCustomPath" and when It doesn't find it an exception will be thrown.
    If the non-existing url is in some static file like .css or .js or the html of the page you can get a lot of these exceptions in just a few seconds if the web server is under a heavy load.

    The solution is simple - just remove the default route and add explicitly routes with the controllers you actually use. By doing that you'll get a 404 without the exception.

    Posted by Branislav Abadjimarinov on October 26 at 1:09 PM

  4. Intro post

    Big Hi to all who are reading this. This is the first "post" (more like a welcoming message) in my newly created blog. I've been in the IT and programming business for some time by now but I've never had the idea of starting a professional blog. There are three main reasons for this. First, I'm more like a "suffer in silence" type. Second, I wanted to gain some more experience before speaking as an authority on professional subjects. And last when I started I thought that the last thing the world (wide web) needs is another blog on technical stuff. But things change and so does my opinion. With the years I've started to trust in the community and finally decided to create what you're reading at the moment.

    To cut the long story short - this blog will be mainly (if not fully) dedicated to my professional interests, namely - programming, software architecture, Microsoft and open source technologies and applied science (artificial intelligence mainly).

    Posted by Branislav Abadjimarinov on October 19 at 6:08 AM

© Copyright 2017 Powered by AtomSite 1.3.0.0