Ian Blackburn

January 2006 Entries

Taking a web app offline

This trick has been mentioned on blogs before but it is such a useful and little documented feature I though it was worth a note.

If you place a file name App_Offline.htm in the root of your asp.net 2 application then all requests will result in this page being displayed.

Perfect for doing maintenence and keeping your users informed, just remember that the page will be delivered from the requested page location (e.g. it could come from a subfolder not the root) so make sure any references to resources, like images or stylesheets use absolute or root relative paths.

HTH

Ian

Comments are disabled for this blog - but please feel free to comment via the contact page

Live.Config > Web.Config in Web Deployment Project

The new Web Deployment Projects holds the promise of making deployment of web apps a doddle, and includes neat functionality to replace sections of web.config with versions for your live deployment.

See ScottGu's post here for details

It still has lots of benefits, however in the current release it seems the web.config replacements don't seem to work with sections other than connectionStrings, at least that was my experience.

However since the project is based on MSBuild you can easily customise the experience.  Right click the deployment project and select "Open Project File" to get to the MSBuild config.  Then make the changes you want.  In my case I reverted to having a full live.config file as well as web.config  and in deployment I replace web.config with live.config using the following:

<Target Name="AfterBuild">

<Copy SourceFiles="$(MSBuildProjectDirectory)\Release\live.config" DestinationFiles="$(MSBuildProjectDirectory)\Release\web.config"/>

<Delete Files="$(MSBuildProjectDirectory)\Release\live.config"/>

</Target>

HTH

Ian

Comments are disabled for this blog - but please feel free to comment via the contact page

Live Local vs Google Maps

Just noticed the Windows Live Local (http://local.live.com/) now has street level mapping for the UK - something which wasn't present in the initial releases.

It also has a very rich UI and support for things like adding pushpins with a right click, a scratchpad, and mouse wheel support for zooming.  In fact the UI is some way ahead of that offered by Google maps (maps.google.co.uk) IMHO.

If you want to use map services like these on your commercial site though, the choice between Google Maps and Local Live comes down to business models.  Where-as Google Maps will eventually place ads on your maps, (see http://www.google.com/apis/maps/terms.html), Local Live will, I believe used transaction based fees and no ads.

HTH

Ian

Comments are disabled for this blog - but please feel free to comment via the contact page

Trying not to google

I have been trying to give other search engines a fair share of my queries.

This isn't benevolence, just a desire to expand my search horizons!

So I have at last installed the Windows Desktop Search which also gives you a MSN search from the task bar, and I have been using that.

But it's sort of hard.

The UI is nice and it all works well, but the search engine is just not as relevant.  For example I am used to Googling for resources that I know exist - it has become a sort of resource management tool for me.  So when I recently wanted the url for Reflector I typed in that word in the MSN and expected it to come out tops like in google - it was not there, other related things where like a VS add-in for reflector but not the actual URL to the tool itself.

No joy in yahoo, excite, or other search engines too.

Not very comprehensive or scientific sure - but for me this (with other day to day examples) means either I have become very tuned to the way google works, or google has a weired ability to understand my intentions clearer than other search engines.  Which is why I guess it is still the number 1 search engine...

Ian

Comments are disabled for this blog - but please feel free to comment via the contact page

Connection Strings and Typed DataSets - explanations (and security notes)

I have been impressed with the improvements to the DataSet Designer and the new TableAdapters in VS2005.  So much so that I have used them on a smaller recent project to create the DAL rather than my current favourite O/R mapper LLBLGen (If you haven't tried them yet, see ScottGu's great introduction).

One of the features of course is the fact that it creates a typed dataset simply by dragging a table from server explorer onto the design surface.  You can then modify properties and configure the generated Table Adapter or add additional queries.  You can also preview the results of command.  All this requires a connection to your database, and where the connection string is stored for this and then used elsewhere has caused some confusion here.  So where exactly is the connection string for this stored?

Well if you are using a separate class library project to create this, then a couple of things happen.  When you drag the table onto the dataset designer VS creates a Settings class under Project > Properties > Settings.settings > Settings.Designer.cs in solution designer and also adds an app.config file.  If you look inside these you may be surprised to see that the connection string is stored in both places.  The settings class with have something like this:

[global::System.Configuration.ApplicationScopedSettingAttribute()][global::System.Diagnostics.DebuggerNonUserCodeAttribute()][global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)][global::System.Configuration.DefaultSettingValueAttribute("Data Source=Server;Initial Catalog=Database;Persist Security Info=True;Use" +"r ID=fred;Password=password")]

public string MyDataBaseConnectionString {

get {

return ((string)(this["MyDataBaseConnectionString"]));

}

}

You will note that the connection string is stored as a default setting for the property

And the app.config will have something like this:

<add name="Bbits.Forum.Properties.Settings.MyDataBaseConnectionString"

connectionString="Data Source=Server;Initial Catalog=Database;Persist Security Info=True;User ID=Fred;Password=password"

providerName="System.Data.SqlClient" />

Editing the property using the Settings tab in the property window for the project will update both these places.

So far so interesting.  But what happens when we reference this library from another project?  And ultimately from our front end?  Well as you may know the app.config will not be kept with the referenced assembly so that can be ignored.  However the settings class has this connection string as a default so that means the Dal will be able to connect to the database without any more work.  That also means there is a potential security risk if you are not aware of this. Your connection string is not encrypted here and anyone could use a tool like Reflector to see the details.  So your best choice here is to make sure that you have used a trusted connection for database connections in this project.  That way you are not potentially exposing any database credentials.

Of course a trusted connection is likely to work in the design environment but not in the app.  So how do we override this connection string from web.config (or a windows app's app.config)?  That's simple: just copy the connectionStrings entries from your app.config in your class library into your web.config and change the values to the correct one.  You can then go ahead and encrypt this section for your release deployment

Hope this helps

Ian

Comments are disabled for this blog - but please feel free to comment via the contact page

Pair programming's new name!

Don't call it that - you'll get negative comments from anyone who hasn't tried it.

Instead adopt a phrase I heard on a recent webcast:"Play the Test-Driven Development Pairing Game" (https://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032287655), and that is:

"Real Time Code Review"

Now doesn't that sound easier to swallow and adopt?

Give it a go...

Cheers

Ian