Saturday, December 18, 2010

In Entity Framework, no method for deleting collection.

Have to delete object one by one. :(
Reference:
http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/2fa38cb9-8815-4767-ab17-04b424f3af57/

Friday, December 17, 2010

How to improve ASP.Net Performance 1: Check list for web.config file

1. Ensure Pages Are Batch Compiled
<compilation batch="true" />

2. Disable debug
<compilation debug="false" />

3. Disable Tracing
< trace enabled =”false” pageOutput="false"/>

4. If use IIS 7, please add following section into web config file to Cache static files
    <staticContent>
      <clientCache httpExpires="Sun, 29 Mar 2012 00:00:00 GMT" cacheControlMode="UseExpires" />
    </staticContent>

How to improve ASP.Net Performance 2- Coding guideline

- Check Page.IsPostBack to avoid unneccercery databinding
- Try use Repeater Control first. Viewstate in DataList, DataGrid, and DataView controls is huge sometime, although event handler is very covernient
- Prefer Transfer over Response.Redirect
- Check HttpResponse.IsClientConnected before performing a large operation

Wednesday, December 15, 2010

How to fix Invalid viewstate and Validation of viewstate MAC failed in asp.net?

There are couple of errors in asp.net related to viewstate
1. System.Web.HttpException: The client disconnected. —> System.Web.UI.ViewStateException: Invalid viewstate.
2. System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. —> System.Web.UI.ViewStateException: Invalid viewstate.

How to fix?
1. Check HttpResponse.IsClientConnected in page load event, if not, logoff user.
2. Check Application Pool Recycling IIS setting to avoid recycling is less likely to occur at peak periods
3. put machineKey section into your web.config (http://www.aspnetresources.com/tools/keycreator.aspx)
Such as:
<machineKey
validationKey="80FE3D40B4CDD7FBC1DC32FA0DC87C83586B651214A19F4BC140970DEAE7F99A6B24D2323DB2088E472194BF14CB996062B41F9C2D3A4D821091AA53282F55D5"
decryptionKey="DA085C28238653E0C85994B40AB4208236E0E814BF698F9C202A80901C00F613"
validation="SHA1"
decryption="AES"
/>

References:
1. Intermittent Invalid Viewstate Error in ASP.NET Web pages
http://support.microsoft.com/default.aspx?scid=kb;en-us;555353&sd=rss&spid=6351
2.ASP.NET state management: viewstate
http://www.aspnetresources.com/articles/ViewState.aspx#

Top 50 Programming Quotes of All Time

http://www.junauza.com/2010/12/top-50-programming-quotes-of-all-time.html