Lots of Free Images and Icons with Visual Studio 2008 Image Library

Microsoft has shipped a great image and icon library with Visual Studio 2008. This library is available at following location:-

C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary.zip

Here is what is inside that zip file:-
You can use that icon free of cost in any of your projects. But there is one note which I found in extracted folder. Here is the text:-

As part of a visual language, the following images (or any part of the images) must be used in a manner consistent with the name of the image file.

Hopefully it will help you. Happy coding !!!

How to restart your web application

Generally we all use cache to improve our website's performance. Caching is really useful when we are frequently displaying data which rarely requires changes. But, sometime client request an immediate change in cache entries and we have no option to manually run IISReset or change the contents of web.config file to clear all the cache.

In below code, I am sharing different approaches which can help you:-

namespace Utilities.General

{

    public static class Utility

    {

        public static bool RestartAppPool()

        {

            //First try killing your worker process

            try

            {

                //Get the current process

                Process process = Process.GetCurrentProcess();

                // Kill the current process

                process.Kill();

                // if your application have no rights issue then it will restart your app pool

                return true;

            }

            catch (Exception ex)

            {

                //if exception occoured then log exception

                Logger.Log("Restart Request Failed. Exception details :-" + ex);

            }

 

            //Try unloading appdomain

            try

            {

                //note that UnloadAppDomain requires full trust

                HttpRuntime.UnloadAppDomain();

                return true;

            }

            catch (Exception ex)

            {

                //if exception occoured then log exception

                Logger.Log("Restart Request Failed. Exception details :-" + ex);

            }

 

            //Finally automating the dirtiest way to restart your application pool

 

            //get the path of web.config

            string webConfigPath= HttpContext.Current.Request.PhysicalApplicationPath + "\\web.config";

            try

            {

                //Change the last modified time and it will restart pool

                File.SetLastWriteTimeUtc(webConfigPath, DateTime.UtcNow);

                return true;

            }

            catch (Exception ex)

            {

                //if exception occoured then log exception

                Logger.Log("Restart Request Failed. Exception details :-" + ex);

            }

 

            //Still no hope, you have to do something else.

            return false;

        }

    }

}


To implement above case you can create a dummy page i.e. RestartApplication.aspx or add a querystring parameter to your existing page like Home.aspx?RestartPool=true. Feel free to share your thoughts with me. Happy Codding !!!

Microsoft has released Visual Studio 2010 Service Pack 1 (SP1)

Microsoft has released long awaited service pack 1 for Visual Studio 2010. You can download this from here.

This Service Pack includes number of feature enhancements along with the bug fixes. Major enhancement for me is the HTML 5 support and IntelliTrace (formally known as Historical Debugger) for SharePoint.

Here are some of the major enhancements:-
General
  • Many Bug Fixes
  • Help Viewer 1.1
  • Sliverlight 4 Support
  • Basic Unit Testing support for the .NET Framework 3.5
  • Performance Wizard for Silverlight
  • IntelliTrace for 64-bit and SharePoint
  • Detecting mixed-mode installations
  • Software rendering (for Xp and Win2k3)

Web development
  • IIS Express support
  • SQL Server CE 4 support
  • Razor support (Introducing "Razor")
  • Web PI integration
  • Deployable dependencies
  • HTML5 and CSS3 support
  • WCF RIA Services V1 SP1 included

XAML Editor/Designer
  • Go To value definition
  • Style IntelliSense
  • Data source selector
  • Advanced grid commands
  • New Thickness Editor
  • Sample data support
  • Increased stability

C++
  • MFC-based GPU-accelerated graphics and animations
  • New AMD and Intel instruction set support
  • Visual Basic Runtime embedding
For more details on above items visit Description of Visual Studio 2010 Service Pack 1. Also visit ScottGu's Blog for more details.

Also Microsoft has release Service Pack for TFS 2010. If you are using TFS then it is a must have for you. For further details you can go to Brian Harry's blog.

How to implement Cookieless Session in ASP. Net

By default ASP.Net relies on cookies to store session id. Cookies are actually a text data which is stored in browser. Generally cookies are not considered a safe way to store information. Also there is a chance that browser have disabled the cookies and in that case our application wont work on that browser.

To avoid such situation, we can use Cookieless session. To implement that you just need to set cookieless attribute to true in your session tag. Here is how you can do this:-
<system.web>
  <sessionState mode="InProc" cookieless="true" timeout="120" />
</system.web>

Once you have done that your URL will contain the session id, here is the snapshot of URL before and after implementing cookieless=true:-
As you can see that in the URL session id is visible.

Feel free to share your comments, Happy Codding !!!

How to Clear all elements from Cache

There are many situations when we want to clear contents of the cache in our ASP. Net application. Here is a quick and dirty way to remove all the contents from our cache.

        /// <summary>

        /// Clears all the data from Cache

        /// </summary>

        public void ClearCache()

        {

            try

            {

                List<string> keyList = new List<string>();

                IDictionaryEnumerator CacheEnum = HttpContext.Current.Cache.GetEnumerator();

                string cacheKey;

 

                //Read all the keys from cache and store them in a list

                while (CacheEnum.MoveNext())

                {

                    cacheKey = CacheEnum.Key.ToString();

                    keyList.Add(cacheKey);

                }

 

                //Remove entries from cache

                foreach (string key in keyList)

                {

                    HttpContext.Current.Cache.Remove(key);

                }

                keyList.Clear();

                Response.Write("Cache Cleared");

            }

            catch

            {

                Response.Write("Cache NOT Cleared");

            }

        }


General I create a page name ClearCache.aspx and call above function in page_load method. So when ever I want to clear cache's contents I just call that page using URL.

Feel free to comment. Happy Coding !!!