Microsoft, Yahoo! Change Search Landscape



Global Deal Creates Better Choice for Consumers and Advertisers


SUNNYVALE, CA and REDMOND, WA - 29 July, 2009 - Yahoo! and Microsoft announced an agreement that will improve the Web search experience for users and advertisers, and deliver sustained innovation to the industry. In simple terms, Microsoft will now power Yahoo! search while Yahoo! will become the exclusive worldwide relationship sales force for both companies' premium search advertisers. More...

Why .Net sessions are terminated/loss unexpectedly

There are many cases when ASP.Net website works great in development environment but as we migrate our website to production server, it starts giving unexpected session timeouts. This article discuss those problems and provide solutions to resolve them.

Here are some of the reasons why this happens:- 

Cause 1: IIS Settings:
1- Application Pool is recycled. - We will know this looking at the system logs
2- IIS/worker process is restarted. - System logs will tell this as well
3- Application Domain is restarted. - We need to monitor for application restarts for the ASP.NET counter in perform to check this.
4- IIS worker process can get recycled depending on the configuration, low on virtual memory, crash due to unhanded exception etc.

Resolution:
1- Goto Start->run->inetmgr->Application pools.
2- Select your application pool and right click -> properties.
3- And see the settings for Recycle worker process (in minutes), set an appropriate value there.
4- Alternatively you can recycle your process when your site generally stays idle i.e. you can select 'You can set values in Recycle worker process at time' and give appropriate time to recycle process.

Cause 2: Modifications in Application Contents:
1- Bin folder of the application is modified.
2- Web.config or the machine.config is modified.
3- Global.asax file is modified.
4- Something in the code is causing session loss, it can be anything like you are adding/removing files in your application folder through code e.g. uploading images. You will need to look into the code to have a fix on this. Like Session.Abandon() or Session.Clear();

Resolution:
Try stopping anti virus software on server and see that session as loosing frequently or not. If problem solves after that then Exclude the anti virus scanning from the IIS/ASP.NET default folders and your application folders.
a- <drive>:\WINDOWS\system32\inetsrv
b- <drive>:\WINDOWS\assembly\GAC_32
c- <drive>:\WINDOWS\Microsoft.NET\Framework\
d- Any application directory containing web.config files, global.asa or global.asax, .net assemblies, and/or other web content which your web apps use.

Check your code, that if your application looses session after a particular operation i.e. you might be changing the contents of your Bin folder or modifying web.config file through your code.

Cause 3: Application is hosted in Shared Server or in Web Farm/Garden:
If your application is hosted on a shared server where other applications are also running on the same server then it might be chances that due to other applications IIS is restarted and causing frequent session loss in your application.

Also if your application is hosted in a Web Garden or Web Farm, then you will also notice frequent session loss. E.g. if first request from user is process by server/process 1 and second request is processed by server/process 2, then session will also appear blank.

In both the cases you can go for a seperate state managment.

Resolution:
You can configure a seperate state server, in which session will not lost due to IIS restarts or server/process switching. First configure state server in your machine. For details and configuration of state server see How to Configure Asp.Net State Server.

Also change your web.config file like this:-
<configuration>
  <system.web>
    <sessionState mode="StateServer" cookieless="true" timeout="30"/>
    </sessionState>
  </system.web>
</configuration>

How To Get The IP Address of Users using ASP .Net


If you want to track or analyze who is accessing your website, you can easily do this by capture the IP address of an incoming connection to your aspx page.
Here is the Code to access user's IP Address

Label1.Text = Request.ServerVariables["REMOTE_ADDR"];

How to Optimize Web Site Performance


  1. White Space Filtering through HTTP Module.
  2. Merge all inline styles and multiple CSS into one big global css file.
  3. Merge all inline javascripts and multiple javascript files into one big .js file and add reference to this file whenever you require.
  4. Minify JavaScript and CSS files using CSS Optimizer and Free JavaScript Optimizer or any other tool which you like.
  5. Try using less images in your web page.
  6. Optimize your images with image optimizer I use Trout's GIF Optimizer to optimize gif files. PngOptimzer to optimize my PNG files, both the optimizer does not effect the quality of your image.
  7. If your pagesize is increasing because of ViewState then try to save viewstate on server side. Here is a simpe example to Save ViewState on the File System
These six steps really helps your site in loosing the weight and they do not take much effort at all. After implementing these six steps see the performance of your application. If after that you are not satisfied enough then try following links:-
10 ASP.NET Performance and Scalability Secrets
Performance Optimization of ASP.NET Applications on Client-side

Also take a look at 15 Tools to Help You Develop Faster Web Pages.

Save Files in Database or in File System

When we talk about design some times it is bit tricky to decide wether to store file in database or store file at file system. Here are some advantages of both the aproaches:-

Storing Files on File System
  1. Your database size will increase rapidly, and backup size will also increased in same proportion.
  2. You can access files from different ways (i.e. FTP or Web Browser)
  3. Database such as Access or MSDE and Sql Server 2005 Express edition(I think it is 4GB) is limited to 2GB size.
  4. In case your database is corrupted, even then you can access the documents.
Storing Files on Database
  1. Better Security since database have a very good security mechanism.
  2. If Files are stored outside database, then it is a chance that you delete the record from database and do not update the file on file system. Which might end up in some inconsistent state.
I strongly recommend to store images on file system. Comments are welcome.