Zip Compressing ASP.NET Session

Zip Compressing ASP.NET Session

December 1, 2008 14:43 by pradeep.mishra

Here are links to a very good articles on how to compress session so that memory on computer may be saved.

Scott Hanselman posted original entry here

A modified useful version was posted by Al Pascual here

Hope this helps!

 

 


Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Best way to end user session in asp.net

Best way to end user session in asp.net

September 11, 2008 20:11 by pradeep.mishra

Session is very important state management tool in asp.net. You fill in this object with lots of user specific information when user requests a certain page e.g. Logged in user information like name, emailId etc can be stored after the sucessfull login. However for better performance we must make sure that all the objects are removed from the session when we don't need them. So question arises what's the best way to end user's session in case user logs out. Session object have two method implemented to straight away clear all the objects in session. those are...

 Session.Clear(), Session.RemoveAll()

 Eventually these two methods are serving the same purpose but I am still not able to figure out what's the difference between the two. Seems there is some legecy code left by microsoft developers :-). If you know the difference do let me know.

There is one other method called Abandon() which must be used in case user logs out. Abondon method marks the current session for deletion as soon as user moves to next page. So it is always good to use Session.Abandon() in the logout event. In this way the same session object can not be reused in subsequent request. Let's take an example

   1:   
   2:  Session["UserId"] = "user@noesispedia.com"
   3:  Session.Abandon()
   4:  Response.Write((string)Session["UserId"] )

Session is still accesible in this page however if you try to acess userId in next page it won't be available.

One more point I would like to make here i.e. Session_Start event will be raised in case session is abandoned however if you don't call abandon method and just use Clear() session object won't be destroyed even after logout and Session_Start event will not be fired as session still exists in memory. To summarize use

   1:   
   2:  Session.Clear()
   3:  Session.Abandon() 
   4:  //Redirect to logout page. 

Hope this helps! kick it on DotNetKicks.com

Currently rated 3.7 by 11 people

  • Currently 3.727273/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Solution to error: asp.net ajax extension setup wizard ended prematurely

Solution to error: asp.net ajax extension setup wizard ended prematurely

April 17, 2008 00:59 by pradeep.mishra

I faced this problem while upgrading .net 2.0 website application so that it may be used in VS 2008 but target framework as .net 2.0 and not 3.5. When I tried to compile the application I got following error.

'Could not load assembly or type System.Web.Extension....". I figured out that I don't have Asp.Net ajax extension installed. When I tried installing ajax extensions I got the title error again and again. After some googling I applied various suggestions like run the msi as administrator (FYI I was using VS 2008 in Windows Vista). Finally one solution worked i.e. the service Ngen was not running in my machine due to which installation action was being rolled back. So make sure you have this service running before you install Asp.net AJAX 1.0. See this forum for more info...

http://forums.asp.net/t/1069586.aspx?PageIndex=2

As suggested by Louis.Lu there is another work around if above method doesn't work

------------------- 

hello, i'm from china, my english is nood good,

i think i could help you.

first, you double click "ASPAJAXExtSetup.msi", copy the following files to other places before the installation has errors.
  C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025
      AJAXExtensionsToolbox.dll
      System.Web.Extensions.Design.dll
      System.Web.Extensions.dll

second, copy the above files to "C:\WINDOWS\assembly"

finally, you go installation "ASPAJAXExtSetup.msi" again.

I succeeded like this.

good luck

 ----------------

 

 


Currently rated 4.5 by 4 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Postback not working in an update panel having validators

Postback not working in an update panel having validators

March 26, 2008 23:47 by pradeep.mishra

Problem: Try creating one form inside an update panel. Put some validators like RequiredFieldValidator etc. Also put in LinkButton insite the update panel. You will notice when you click on the linkbutton nothing happens.

Reason: When you try to submit the form or doing postback, a few javascript client side functions are raised due to validators and due to some error validation fails and postback event is not raised. 

Solution: There is some problem with the code validators have been written. Check the following post http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

So untill some windows update is not release you're stuck with it. However there is a work around with some limitations. Set the enableClientScript = "false" for all validators. This will disable the client validation and post back event is raised. Since any way you are using update panel, the validation will occur on server side and you will get the same result and without noticeable delay. With this work arround you are losing the client validation but I think still it's okay because you will still be able to use the validators inside update panel. 

Hope this helps! 


Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

How to show google mail like loading image/please wait... message while page dat...

How to show google mail like loading image/please wait... message while page data loads

March 21, 2008 02:45 by pradeep.mishra
For a better user experience you would your users to see please wait message while browser render the page completely. Here is the one solution to the same problem. Let's create a master page called Site.master and a web content form as demo.aspx.
   1:  Loading Demo
Demo.aspx is the web content form which fetches data from a database.
   1:  <!-- Code to fetch data from a database -->

To show loading message add following code to the code behind of master file Site.master.cs

   1:   
   2:  protected override void OnLoad(EventArgs e) 
   3:  { 
   4:  if (!IsPostBack) 
   5:  { 
   6:  Response.Buffer = false;
   7:  Response.Write("
   8:  <div style="top: 2px; left: 2px; width: 83px; height: 19px; text-align: right; background-color: orange">
   9:  Please wait...
  10:  </div>
  11:  "); 
  12:  Response.Flush(); 
  13:  } 
  14:  base.OnLoad(e); 
  15:  } 
  16:  protected override void Render(HtmlTextWriter writer) 
  17:  { 
  18:  if (!IsPostBack) 
  19:  { 
  20:  Response.Clear(); 
  21:  Response.ClearContent();
  22:  } 
  23:  base.Render(writer); 
  24:  } 
in the Site.master.aspx file add following javascript at the end of the file.
   1:   
   2:  try{
   3:  var divLoadingMessage = document.getElementById("divLoadingMsg");
   4:  if (divLoadingMessage != null && typeof(divLoadingMessage) != 'undefined') 
   5:  { 
   6:  divLoadingMessage.style.display="none"; 
   7:  divLoadingMessage.parentNode.removeChild(divLoadingMessage); 
   8:  } 
   9:  }
  10:  catch(e){} 

That's it now all your pages using Site.master will be showing Please wait.. message when the page starts loading. Of course instead of putting a message you can put a nice web2.0 loading image in between divLoadingMsg tags.

So how does this works? The onLoad event of master page will be called before any of the content web form's Onload event. as soon as master page loads div tag becomes visible. After the page has loaded completely the script written at the end of the master page hides the div tag. so simple isnt't it.Hope this helps! [Thanks to lijo, my friend, for this nice solution] kick it on DotNetKicks.com

PS: This is my old post from http://technoesis.wordpress.com. I have imported the comments as well


Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5