Wednesday, 31 March 2010

One way to trigger a restart of your ASP.NET web application

Last week I built some code that dynamically published new URL rewrite rules into a file included into the web.config file of a .NET web app/site. It was done using classic ASP as it was part of a client's in-house CMS, and this part of the CMS enabled their end user to add their own friendly URLs to the site.

It became apparent early on that editing this included file automatically restarted the whole app, which was an undesirable situation given that customer sessions would be lost. My solution was to make use of the restartOnExternalChanges attribute of the section element in the web.config file that referred to the Intelligencia UrlRewriter:

<section name="rewriter" requirepermission="false" restartonexternalchanges="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter">
This meant that any edits to the included file wouldn't trigger a restart. But they also wouldn't be recognised until a restart. So then I had to give the user a way of restarting the app when they wanted to. So this time I used a similar entry in the web.config but with a contrary restartOnExternalChanges attribute setting:

<section name="rewriterRestarter" requirepermission="false" restartonexternalchanges="true" type="XmlConfigurator.XmlConfigurator, XmlConfigurator">
And later in the file:

<rewriterRestarter configsource="Config\urlrewriterRestarter.config">

With the right permissions set, the ASP CMS could make a simple edit to this new include and automatically trigger a restart.

Of course, we could have just edited the web.config directly to trigger a restart, but relaxing the permissions to achieve this just didn't seem right.

Tuesday, 23 March 2010

Automatic stored procedure generation using Visual Studio

I was recently working in classic ASP using a client's in-house content management system. I had worked on this before and recalled the production of the stored procedures to be one of the most laborious parts unless some third-party tools like Code Author were used.

I wondered if there was a way of generating stored procedures using Visual Studio, and sure enough there is....

Under Add new item select Dataset, and name it whatever you want. A new .xsd window will appear. Right click in this and choose Add > TableAdapter. In the next window point to your database.

And then there's the important bit:

Select Create new stored procedures. In the next window insert a 'SELECT * FROM MyTable' statement and click Next. Then you can name the Select, Insert, Update and Delete sprocs. At this point I chose Preview SQL Script which allowed me to cut and paste the generation code into SQL Server Management Studio. You could of course continue with the process and allow VS to do the generation for you.

At the end, delete the .xsd file as you don't need it.

Friday, 5 March 2010

Intelligencia URL rewriter with IIS6 - enable wildcard mapping

This is one thing I always forget to do, and then forget how to do. Well not any more, coz it's blogged!

To get the Intelligencia URL rewriter to work on your site you need to enable wildcard mapping for the site in IIS6. In IIS Manager go to your website, right click on Properties, go to the Home Directory tab, and then the 'Configuration' button near the bottom. In the bottom box of the next window insert the aspnet_isapi.dll file, which normally for me is found here:


And for some reason, in the Add/Edit window I always need to uncheck 'Verify that file exists' to make it work. That's it then. Simples :)