Error `Session state has created a session id, but cannot save it because the response was already flushed by the application.` di ASP.NET

Beberapa waktu belakangan ini saya sering menemukan pesan error:

Session state has created a session id, but cannot save it because the response was already flushed by the application.

Padahal setelah check recheck di semua bagian dari page tidak ditemukan command Response.Redirect atau Server.Transfer. Bilapun ada, saya sudah menonaktifkan semua command tersebut.

Tracking di pesan error yang ditampilkan agak kurang bermanfaat, karena semua pesan error yang ada menunjukkan posisi error berada di code ASP.NET bukan di code saya.

Pesan error ini pun muncul hanya pada saat session baru kick-in. Bila page di refresh maka pesan error tersebut akan hilang.. lenyap. So, dugaan kuat error ini berhubungan dengan event Session Start. Akhirnya saya pun menilik ke arah Global Application Class (global.asax) dan melakukan tracing di event Session Start. Setelah trial dan error akhirnya terpikir untuk mencoba mengakses nilai SessionID dari object Session dengan asumsi bahwa bila nilai SessionID sama dengan null berarti session id memang belum dibuat saat aplikasi mulai. Untuk melakukannya, saya meletakkan kode:

if (string.IsNullOrEmpty(Session.SessionID))
           throw new Exception("No new session created");

pada event Session_Start di file global.asax.

Build and run the application then voila… error tersebut tidak pernah muncul lagi.

Related Posts

Server.Transfer Bug
I’m really excited after toying around with Server.Transfer() procedure for sometimes. It has...
Converting Pentax Optio S5n M4S2 Video file using VirtualDub
Digital Camera (digicam) such as my Pentax Optio S5n and Casio Exilim EX750 with MPEG4 capability is...
Migration to WordPress
Finally.. yes finally i migrate to wordpress too. After succesfully help my wife blog migration to WordPress,...
VMWare Shared Folder dan `Failed to start monitoring changes` error di Visual Studio
Setelah cukup lama bermain-main dengan Microsoft VirtualPC 2007 akhirnya saya grow tired dengan segala...

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>