Navigation

Search

Categories

On this page

Removing unused CSS Classes from your web application
Fixing Gaps in Corners while using Ajax control toolkit RoundedCorners Extender
1st look at the Asp.Net MVC Framework
Using MySQL with asp.net for authentication/authorization
Login Page loses styles when using Forms authentication

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 22
This Year: 12
This Month: 0
This Week: 0
Comments: 7

Sign In

 Wednesday, October 01, 2008
Wednesday, October 01, 2008 7:46:35 PM (Mountain Standard Time, UTC-07:00) ( asp.net | css | utilities )

Most of you might have seen that while working on a Website project, the CSS gets harder to maintain as the site ages. This might be due to new developers coming in to the project, removal of UI elements (but not the corresponding CSS), refactoring and so on. I think it is a good idea to revisit and clean your css every few weeks before it becomes totally unmanageable. In this post, i am going to outline 2 ways to do so
There is a great Firefox plugin called Dust-Me Selectors which can test individual web pages or spider your Website to find unused CSS selectors. As you navigate from page to page in your Website, it maintains a list of unused CSS selectors that you can remove.
If for some reason you cannot use the plugin, or would like to be more sure, I have also created a small utility (for personal use) that can parse a CSS file to create a list of defined classes and go through the code base to determine which of those classes are actually being used. This utility usually gives me a list of unused CSS classes with an accuracy of greater than 95%. It cannot give a 100% accurate output in cases where the css classes are being assigned dynamically in JavaScript or server side code (it catches some of them, but not all). But it gives you a great starting point. I normally search my codebase for the CSS class name before commenting it out from the CSS file to be sure its not being used in the code anywhere. I delete the commented out CSS classes after a couple of releases if I do not see any issues.
You can download the utility (named CssCleaner) from here. Please remember that this does not come with any kind of warranty, I am just sharing this so that it can be helpful to somebody in a situation similar to mine.
CssCleaner is pretty simple to use. Download the app, unzip it to a folder on your system. You should see 2 files - CssCleaner.exe and CssCleaner.exe.config. The config file is needed by the application and is present to make a couple of things configurable. I'll talk more about it in a second.


After you run the application, click on "Choose Application Folder" and choose the code base folder for your Website. Click on "Choose CSS File" and select the CSS file that you want to analyze. Change the File Filter if you would like to process files different from the default types. Leaving that textbox blank processes all files. Click on "Process" to run the utility. The unused classes get loaded on the right hand side. In my use, the tool has been pretty fast.
If anybody is interested in the implementation, i use a parser/scanner to parse the CSS file similar to this. Then I go through all the files in the code base, building a list of  used CSS classes using a regular expression. The regular expression is picked up from the config file, so you can tweak it as you find suitable. The other thing picked up from the config file is the list of default file types to search for. It then compares the used CSS class list against the available CSS classes and displays the unused classes list.
If you have any suggestions for the tool, or find any bugs, please leave a comment or email me (latish.sehgal at gmail dot com) and I'll try my best to implement it. I hope that you find this tool helpful.

 Wednesday, August 20, 2008
Wednesday, August 20, 2008 4:59:17 PM (Mountain Standard Time, UTC-07:00) ( ajax | asp.net | extenders | Rounded Corners )

We noticed gaps in the borders for some of our controls while using the RoundedCorners Extender. This was a big headache since it seemed to work fine on some pages. I have included a sample image below.

We finally figured out that on the pages where it was not working, we were injecting some diagnostic information into our html as comments. Since this was being inserted before the doctype, it was sending IE into quirks mode and that was causing the trouble. Updating the code to insert comments after Doctype declaration fixed the issue.

Hope this helps somebody out there:).

-Latish Sehgal

 Monday, December 17, 2007
Monday, December 17, 2007 1:47:27 PM (Mountain Standard Time, UTC-07:00) ( asp.net | MVC )
 Ok!! So everbody and their mother have already blogged about the new MVC Framework released with Asp.Net 3.5 Extensions preview 1 week ago, but i just got time to try it out. Its pretty different from the WebForms model, and is not meant to replace it in any way. Its an alternative that promotes test driven design and makes it easy to unit test your code. As per ScottGu, it enforces a clear separation of concerns within applications. In other words, it makes it harder for the developer to make bad design decisions, because it encourages you to keep your layout (view) separate from the data access code (model) and business logic (controller). Also, the URLs in an MVC point to the Controller and not to the view, so it gives you much more control over the URLs in your application. You also do not have the file extensions as part of the url by default, since you are pointing to the Controller class, and you can specify the method (ControllerAction) to call along with the parameters in the URL itself.  The  controller invokes the appropriate view which renders the html.
 
 To learn more about Asp.Net MVC framework, check out the following resources:
http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx
MVC Part1
MVC Part2
MVC Part3
MVC Part4

Its quite a handful for a 1 week old technology preview framework, isn't it!!

-Latish Sehgal

 Wednesday, December 12, 2007
Wednesday, December 12, 2007 11:55:45 AM (Mountain Standard Time, UTC-07:00) ( asp.net | authentication | authorization | mysql )

MySQL database is a good option for projects that need large stable databases but cannot afford the Oracle or MSSQL price tag. The provider model in Asp.Net 2.0 allows us to use MySql with plenty of Out of the Box functionality. When using Forms Authentication, you can just configure the application to use the MySQL provider, and then use the ASP.NET Web Site Administration tool to manage users and roles in your application.

1. Make sure you have installed the latest version of MySQL Connector/Net. This also adds an entry each to the membership and rolemanager providers in the machine.config files behind the scenes.
2. Open the Asp.Net Web Site Administration page, go to  'Provider ' tab and click on "Select a different provider for each feature (advanced)".
3. Select ' ' as the Membership Provider, and ' ' as the Role Provider.


4. Add the connectionstring to your MySQL server under the name 'LocalMySQLServer'.
        <remove name="LocalMySqlServer"/>
        <add name="LocalMySqlServer" connectionString="server=localhost;database=mbs;uid=root;pwd=mbs"/>

5. Goto 'Security' tab and manage your users and roles.

 Saturday, December 08, 2007
Saturday, December 08, 2007 5:24:47 PM (Mountain Standard Time, UTC-07:00) ( asp.net | login | stylesheet )
One of my colleagues faced this problem recently while working on a new asp.net site, where his login page was not rendering as per the default stylesheet whereas all the pages displayed fine once the user logged in. When i looked at his web.config file, i saw that anonymous access was blocked to all resources on the site, and adding an <location> element allowing anonymous access to the images and stylesheets folder fixed the issue.
It looks something like

<location path="img">
     <system.web>
            <authorization>
                    <allow users="*"/>
           </authorization>
    </system.web>
</location>


-Latish Sehgal