# Thursday, December 04, 2008

Removing the scrollbar Page Shift from Firefox

This had bugged me for a while.  A lot of sites (including some of the ones I develop) tend to have a fixed width layout these days and some browsers (IE particularly) 'always' has a visible scrollbar.  This means that the available screen width is constant whether the page scrolls or not. 

Firefox on the other hand (and Chrome/Opera/Safari) seem to have this off by default.  This of course seems reasonable until you have a fixed width, centred layout that 'shifts' when you switch from a non-scrolling to a scrolling page.  It's just a bit off-putting.

Fortunately Firefox is configurable and the following will fix that up for you. (I'm sure the other browsers are capable of something similar but I'm not using them much :) )

  1. Find your profile directory (it's bound to be the 'default' one unless you're developing Firefox addons.  You'll normally find it in c:\documents and settings\username\application data\Mozilla\Profiles\xxxxx.default\
  2. Go to the 'chrome' subfolder and create a file called userContent.css (you'll probably find there's a couple of 'example' files there already.
  3. Add the following (Firefox-specfic) line to the file:

    html { overflow: -moz-scrollbars-vertical !important; }

  4. Save the file, exit Firefox and start her up again.  You should now have a permanent scrollbar which eliminates the page shift. 

posted on Thursday, December 04, 2008 10:51:55 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Wednesday, November 26, 2008

Create SQL Server User and Role Script to execute Stored Procedures Only

I really thought I'd posted this before, but here's a script I use quite often when I need to create a SQL user that needs to just have 'execute' access to Stored Procs. 

This is usually used for web apps where the server is going through as a single user.  I'd encourage anyone to ensure that you always start off with granting the minimum access required and only add more when actually needed.  If you've got different roles in the application (viewer, administrator etc) then create different roles, with a user for each.

The intention is to remove the need to give direct table access (as we only call Stored Procs right?).  The script doesn't actually do the 'grants' for you, but will generate another batch that you can execute if you like.  I prefer to put the grants in the script for each proc/function anyway, just so it's a little easier to maintain, and you can specifically grant access to the 'admin' procs to the 'admin' role, whilst limiting any 'normal' users to the read-only/everyday ones. 

There's satisfaction to be had from an app that connects to the database via an appropriate user, which is in a role that can only do what is necessary for the role, and can't access tables directly.  Not only is it neat, it's also (relatively) secure.

Here's the script...




-- MSIMNER: This script will generate a role and user for SQL Access to a single database
-- The role will have no specific access to read or write tables but will be granted access
-- through execution of stored procedures ONLY

USE <databasename, sysname, MyDB>

DECLARE @UserName VARCHAR(20)
DECLARE @Password VARCHAR(20)
DECLARE @DBName   VARCHAR(20)
DECLARE @Role     VARCHAR(20)

--SET PASSWORD HERE
SET @Password 'ixFg2tfk'

SET @UserName '<databasename, sysname, MyDB>User'
SET @Role     'db_exec_<databasename, sysname, MyDB>'
SET @DBName   '<databasename, sysname, MyDB>'

IF EXISTS(SELECT FROM master.dbo.syslogins WHERE name = @UserName)
BEGIN
    exec 
sp_revokedbaccess @name_in_db @UserName
    
exec sp_droplogin @loginame @UserName
    
exec sp_droprole @rolename @Role

END

--Create User
exec sp_addlogin @loginame @UserName, @passwd @Password
exec sp_grantdbaccess @loginame @UserName
exec sp_defaultdb @loginame @UserName, @defdb @DBName
exec sp_addrole @rolename @Role, @ownername 'dbo'
exec sp_addrolemember @rolename @Role, @membername @UserName


-- The output of this command will need to be run separately - i.e. paste the output into a new window and run... 

--SELECT 'GRANT EXECUTE ON ' + name + ' TO ' + @Role , *
--FROM sysobjects
--WHERE type = 'P'

Colorized by: CarlosAg.CodeColorizer
posted on Wednesday, November 26, 2008 10:10:59 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Thursday, November 20, 2008

Removing references to HttpModules from ASP.NET SubFolders in web.config

If you have ASP.NET applications that live as subfolders of a larger site, you may find yourself with issues when it tries to find assemblies and httpmodules that are referenced in the parent's web.config.

Fortunately this is something you can work around.  Matthew Nolton goes through how you 'remove' these references at the subfolder level using the <remove> element.

This is all fine until you get an even tastier situation like I encountered the other day...

ASP.NET application 'A' lives as subfolder 'B' of both parent site 'C' and 'D'.  The configuration of 'C' and 'D' is slightly different (modules, handlers, assemblies etc).  Why is this a problem you ask?  We were trying to be a bit clever (and failed :) ) by only deploying application 'A' once.  Virtual directories in site 'C' and 'D' both point to the same physical 'A' folder.  This effectively means that the stuff that needs to be removed from 'A' varies depending on which parent site you're accessing.

OK - I could just fix this by duplicating the installation, and varying the configuration but....

You can also remove all modules by adding a 'clear' element as follows...

<httpModules>
     <clear/>
</httpModules>


This is fine, BUT if you're using Session State or any other in-built features that are implemented as httpModules then you'll get exceptions as ASP.NET will give you a 'null' session for instance.

The following is probably a safe list of modules you'd normally need (maybe even only the session for simple apps), so just add them back in after the 'clear'....

<httpModules>
     <clear/>
     <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
     <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
     <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/>
     <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/>
</httpModules>


This is nicer for a couple of reasons
  1. It shows what dependencies the application has on ASP.NET/external features, and...
  2. It gives you the power back to have the application consumed by multiple sites as you've effectively decoupled yourself from the parent's dependencies.

posted on Thursday, November 20, 2008 3:07:59 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]

Minify your Javascript using JSMin to minimise client downloads

This isn't a new thing, but I just came across a C# console app class, ported from JSMin to help with 'minifying' (or uglifying) your Javascript.  You can find it here.

Just create a new C# console app, pass in the 'input file' and 'output file' and away you go...

posted on Thursday, November 20, 2008 11:16:10 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Monday, October 20, 2008

Visual Studio Tips - Selecting Block Text

I was just looking for a way to witch Visual Studio into 'block select' mode - having assumed that it 'must' be possible, and found this pretty useful (albeit old) Visual Studio Tips blog.

My original question was answered here - can't believe it's a nice as holding down alt while you select...

posted on Monday, October 20, 2008 2:17:09 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Saturday, October 18, 2008

Updated My Site

I've been starting to do some 'various' T-Shirt designs on RedBubble.  It's a great site - similar in some ways to Threadless, but a lot more inclusive and encouraging of participation. 

I've made some updates to mattsimner.com, as I thought one page was probably a little light these days - and I also wanted to do a bit of an SEO experiment with cross referencing on all of the sites I update. 

You can see my T-Shirts and other art...

at

Buy my t-shirts or my RedBubble home page

Get creative on redbubble.com

posted on Saturday, October 18, 2008 8:47:52 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]

Updated DeletedOld CodeProject Article

After an extremely long time I've made an update to the DeleteOld console app and updated the CodeProject article.  The original was .NET 1.1 - this one's now 2.0 (I'm not on 3 yet!)

It still does the same things it did - deletes files of a specified age, but now also:
  • Allows files to be deleted 'newer' than a certain age as well as 'older'
  • Allows files to be deleted based on an absolute date (overriding the timeframe arguments)
  • Allows the 'root' path to be preserved if 'remove empty folders' is selected and the path specified is empty.
  • Fixed a bug in Arguments parsing regex as noted by dudik
  • Changed output datetime format to 'full' rather than specific dd/mm/yyyy as noted by a.plus.01
I had a need for the absolute date, so thought I may as well cover off a few other things. 

Hope it's of some use...

You can also see my other CodeProject articles.

posted on Saturday, October 18, 2008 8:32:58 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Thursday, October 09, 2008

Serving SSL from localhost on IIS 5 on Windows XP using Self-Signed certificates

I've probably glossed past this a few times, but it turns out getting SSL working on your dev machine is less painful than you'd think...

  1. install iis60rkt.exe from http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&DisplayLang=en on your local machine. It's intended for IIS 6.0 but it works in IIS 5.1.
  2. Select custom install if you only want to use SelfSSL. Otherwise, install all.There's a lot of other useful stuff there.
  3. Select Programs --> IIS Resources --> SelfSSL --> SelfSSL command prompt
  4. In the command prompt, you'll see a list of all possible command parameters..
    1. Type 'selfssl.exe /V:60'     This indicates the certificate is valid for 60 days
    2. Type Y to answer the question "Do you want to replace the SSL settings for site 1 (default website) ?
    3. Type 'iisreset' to restart IIS.
If your browser prompts something like 'Certification Authority not recognised' (in Firefox), just put the url in the exception list or override the warnings when viewing the page.

Thanks to Ricky for getting this info together.

posted on Thursday, October 09, 2008 9:56:33 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
# Monday, September 29, 2008

More reasons to love JQuery

I've only recently started using JQuery, but needless to say - it rocks!

for those that don't know it's a Javascript library that's basically revolutionising how you write client-side code.  My reasons to love JQuery.

  1. It's open source, well tested and an open design.  This means you write less code and you can rely on functionality just 'working' in different browsers - or gracefully failing if something's not right.
  2. It's really light (especially when 'packed' - 31kb)
  3. It's got a strong community with lots of really cool plugins (just take a look before you start developing that 'widget' in flash)
  4. It plays well with other libraries and code.  you just use it for what you need and plugins sit with other plugins.
  5. It's obviously gaining momentum, as Scott Hansleman announced Microsoft are going to ship it with ASP.NET MVC and Visual Studio (that's a pretty amazing move from Microsoft).
If you're just getting started with it, and you're familiar with Javascript already I'd start with the tutorials.  Some are better than others, but run through the first couple to understand how it works, then scan down the list to find something related to what you need to do.  Typically you'll be wanting to write a plugin, so I found this one quite good for starters.

You should find everything you need in the Documentation

you'll then spend most of your time in the API section, looking for specifics on how to do things. 

posted on Monday, September 29, 2008 11:21:34 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]
# Monday, September 15, 2008

Replacing Notepad with Notepad2

Notepad2 is great - no arguments.  It was only this morning I actually got around to 'replacing' the standard notepad.exe with notepad2.exe.  You'd think it was just a simple rename, but Omar Shahine shows the way...

posted on Monday, September 15, 2008 8:36:04 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]

Using CSS Frameworks to do the heavy layout lifting

CSS is great, until you're faced with a deadline and a broken IE6 layout.  You get the cowboy gear out and - 'Welcome to Hacksville!'  

There's been a growing trend of CSS frameworks recently as people are obviously crying out for 'something' to save them from the madness. 

I'm trying out the 960 grid system at the moment, as it's not too prescriptive and gives me the flexibility I need.

There's a great review of the best frameworks on adactio.  I'm sure there's one to suit almost every need.  Remember they're just the starting point if you're doing serious design, but they'll take most of the pain away, because the heavy 'hack' lifting is done for you...   

Also - more on Wikipedia (Update: 17/09) - BlueTrip's the way to go - best of several worlds - nice.

posted on Monday, September 15, 2008 8:30:41 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]