String Function

Its always a pain when you are can't remember how to do something and then it takes you a few minutes to search for the syntax as google aint smart enough to turn what i think into effective queries.

Anyway i was looking for String.Format

And also i found a string truncate function:

Its always nice.

Update: found these examples too:


.Net 2.0 Code Profilers

When I went to try to profile my application in c# 2.0 I wasn't surprise to see that the old application that I used in 1.1 did not work anymore. These seem to be the current tools for profiling:

CLR Profiler

ANTS Profiler
and last but not least, the most expensive version of VS2005

I will try the CLR Profiler first and if the results are no good/hard to decipher, which I except, I will download the trial of ANTS, as that seems to be the recommended one.


ASP.NET 2.0 EventValidation

When building an ajax enabled folder list view control, ran into a problem where i was clicking on the folder node, which caused a postback to the datagrid control. Trouble was then when i tried to operate on the datagrid control (sort, select) i was getting an error:

The state information is invalid for this page and might be corrupted.

After doing a lot of reading about it, this problem is caused by the event validation feature of ASP.NET 2.0. This is where the items in the datagrid are added to an event validation thingy, so that incorrect values can not be used to postback. Now i can solve it two ways, either by disabling eventvalidation it in web.config:

Or by registering each of the new items that i add to the datagrid for the callback so that event validation works correct:

I will see how easy it is added the validation, and hope that magicajax will correctly handle the updates. Otherwise i will just turn off the security feature as suggested here:


Format Source Code in Blog

I suppose this is the must have tool for posting source code into blogs. A real time saver.

MSDN VirtualPathProvider

So i copied all the code, make the files, make a web application in IIS. Doesn't work, so i have to make a few fixes to the code (ending brackets, change GetData on VirtualFile to use this.VirtualPath, rather than this.Name). Still doesn't work. Finally have to add httphandlers.

<?xml version="1.0"?>
    <compilation debug="true"/>
    <customErrors mode="Off"/>
    <trace enabled="true" requestLimit="100" pageOutput="true" traceMode="SortByTime" localOnly="false"/>
      <add verb="*" path="*.vrf" type="System.Web.StaticFileHandler" />

And still cannot access by "~/", must access by "~/default.aspx".

VirtualPathProvider IIS vs ASP.NET Development Server

One thing that I have found when working in VS2005, is that I can be testing my VirtualPathProviders, and they will all work correctly for unmapped extensions. That is images (jpg, gif), styles sheets (css) and script files (js). Then when I move the application to run in IIS 6.0 the behaviour is different. This is because it seems that IIS does not even dispatch requests for such files to the ASP.NET runtime. So my VirtualPathProviders are not even used. Its strange how the two servers run differently.

The solution for IIS, to this problem is within one of Mark DÂ’Urso's presentations, http://blogs.msdn.com/mdurso/ [VSLive]. It involves adding a Wildcard Application Map in IIS's snapin (application configuration->mappings). With this mapping in place though, the ability to have default documents in a folder is lost. When normally requesting an aspx page, the ISAPI extension takes control from IIS. When you request a file that does not have an ISAPI mapping, IIS just servers the file itself. With the wildcard, all files are palmed off to the ASP.NET application extension. Don't know how this affects load/caching, having all files go though ASP.NET.

Heres what msdn says about wildcard application mappings in IIS 6.0:

Some info on httphandlers when wildcard application mappings are used:

Static mappings for content served by ASP.NET compared to IIS

ASP.NET 2.0 VirtualPathProvider

Wouldn't it be nice in web applications to have all scripts and images embedded in an assembly so that you only had to release one file. Now if you used this common library across more than one project, you may not want to rely upon VS 2005's web deployment project. Each project would then have to be compiled separately.

One method of achieving this would be to use ASP.NET 2.0's VirtualPathProvider. Apparently you should be able to set up certain path's that map to what you want, rather than the filesystem. This could be a database, xml file or in this instance, an assembly.

If I wanted to create an assembly for a client script application, for example a html content editor, that consisted of style sheets, images and script files, the idea would be to map the path, ~/scripts/htmleditor, to a custom VirtualPathProvider. This provider would then read the file from the assembly and return it to the client.

Here are a few links to how to implement: