Archive for the 'asp.net' Tag

  1. Configuring a virtual application within an ASP.NET MVC site

    I recently had to look into how to get requests to /TestApp within an ASP.NET MVC site resolving to another application, instead of picking up the default routing rule and trying to find the Index action on a TestApp controller class. A scenario where this may occur would be setting up a wiki application to run on /wiki off your main domain name.

    First off, we need to ensure that the routing module doesn’t kick in and attempt to handle the request. This can be achieved by making the following change in global.asax of the MVC app…

    routes.IgnoreRoute("{*path}", new { path = @"TestApp\/(.*)" });

    You can then create a new virtual directory in IIS under the main site, and convert it into an application to ensure it’s running in a seperate AppPool etc.

    The final step is to ensure that web application settings in the parent application don’t cascade and get applied to the child application. This is achieved by wrapping all of the main configuration in a location block, and setting inheritInChildApplications to false like so…

    <location path="." inheritInChildApplications="false">
       <system.web>Blah</system.web>
       <system.webServer>Blah</system.webServer>
    </location>

    The most useful reading on this I could find was this forum post.

    Posted at 4:40 pm on 1/06/09

    Tags: , , ,

    Comments: None

  2. ASP.Net Markup Snob

    I tend to get quite sad when people approach ASP.Net and can drag and drop controls and build a site without really thinking about the markup that gets sent to a client. I know that part of their brief is to make it easier for people to build sites, but the added layer of abstraction of using a framework often means that people never gain an understanding of the underlying technologies involved.

    I’ve seen lots of respectable developers work on sites without running validators over their work or nosing around in the markup that is generated. People will learn the interface for consuming a particular server control without ever getting near the HTML. You’ll see posts from beginners along the lines of ‘how do I set the src attribute on an image’ - so you learn to set the ImageUrl property on the server control.

    I tend to approach development in ASP.Net from the other direction… how can I get the framework to generate this markup that I require in the most effective way? I think there should be minimal difference between how you would author a static site, and the generated markup from a dynamic site. Otherwise you’re compromising the quality of the site to accomodate constraints from the framework that you’re using.

    I think ASP.Net is a great framework. However I strongly believe it should be used to build custom controls that serve the specific markup needs you have for a site. Generally if you’re doing things correctly, the actual HTML is purely content and therefore very simple. It’s not actually that much effort to author nice simple custom controls that just serve your requirements and do nothing else.

    A simple example is how all of the ‘free’ server controls will always render an id attribute to the client - generally this will be autogenerated and long and bloated. Firstly this can interfere and make it hard to use ID based selectors in CSS, but also (more importantly) you should only render an ID attribute if you need a hook for styling or behaviour. Otherwise you’re simply bloating the stream of data that gets sent to the client, and wasting bandwidth and server resources.

    I always tend to build a base custom control class where you can specify whether and ID should be rendered, and also whether the ID should be scoped or not. If set to true, the ClientID property gets written to the output stream (the fully qualified value), otherwise the exact ID that was set on the control. The default for rendering the ID attribute is false. This means that the markup does not get bloated with unnecessary information, and as an author you have complete control over the value that gets rendered (so using ID selectors in CSS is back on the cards).

    Posted at 11:26 am on 6/09/06

    Tags: , , ,

    Comments: 2

  3. Atlas or YUI?

    For a little while I’ve been meaning to take a proper look at Atlas, Microsoft’s main offering to help out in building AJAX applications and richer web based interfaces.

    Javascript is definately back in fashion, with a number of libraries popping up to help out with application development. I think overall this is fine, so long as you have an appreciation of what is actually happening under the scenes. I don’t think a library should dictate the way that you build an application, rather enable you to build it more efficiently.

    I’ve started using elements of the Yahoo YUI library which is very impressive. There seem to be a lot of very useful little utility functions available, the kind of thing that you would typically rewrite on each project.

    I’m quite curious about how the Microsoft and Yahoo libraries compare. I’ll post some information about this when I’ve had a chance to look in more detail at Atlas.

    Posted at 12:16 pm on 3/07/06

    Tags: , , , ,

    Comments: None