<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Anas Ghanem </title><link>http://weblogs.asp.net/anasghanem/default.aspx</link><description>&amp;lt;ItemTemplate ".Net Tips" runat="Weblogs.asp.net"  Country="WestBank" /&amp;gt;  
</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Differences between  Web Application Project(WAP) and website Projects when specifying the Type settings attribute</title><link>http://weblogs.asp.net/anasghanem/archive/2008/07/13/differences-when-registering-httpmodules-and-httphandlers-for-web-application-projects-and-website-project.aspx</link><pubDate>Sat, 12 Jul 2008 22:01:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6220462</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/07/13/differences-when-registering-httpmodules-and-httphandlers-for-web-application-projects-and-website-project.aspx#comments</comments><description>
&lt;p&gt;When configuring a custom providers , or registering HttpHandlers and HttpModules , or using any other configurations sections that needs to specify the type settings attribute , you will need to correctly specify the type by specifying a correct&amp;nbsp; namespace and assembly .&lt;/p&gt;

&lt;p&gt;Its not the same for web application projects (WAP) and website projects , i will discuss this difference by providing an example on how to register the httpModule . &lt;br&gt;&lt;/p&gt;

&lt;p&gt;If you are not familiar with &lt;u&gt;HttpModules &lt;/u&gt;and &lt;u&gt;HttpHandlers &lt;/u&gt;, please read &lt;a href="http://msdn.microsoft.com/en-us/library/aa479332.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa479332.aspx"&gt;this&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;And if you are not familiar with the Differences between &lt;u&gt;WAP &lt;/u&gt;and website project , Please read &lt;a href="http://msdn.microsoft.com/en-us/library/aa730880%28VS.80%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx"&gt;this&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/05/08/445742.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2006/05/08/445742.aspx"&gt;this&amp;nbsp;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Difference : &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;b&gt;For WebSite project :&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;when you write a custom &lt;span style="text-decoration: underline;"&gt;HttpModule&amp;nbsp;&lt;/span&gt; in App_Code folder which is inside your website,Then you can register the Custom module in web.config in this format :&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&amp;nbsp;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers1.gif"&gt;&lt;div style="overflow: auto;"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers1.gif" border="0"&gt;&lt;/div&gt;&lt;/a&gt;&lt;/p&gt;
&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/WebSite%20Registerhandlers.jpg"&gt;&lt;/a&gt;
&lt;p&gt;so for example if you write this module in App_Code&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/Website%20RegisterHanler%20example%20vb.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="overflow: auto;"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers5.gif" mce_src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers5.gif" border="0"&gt;&lt;/div&gt;&lt;br&gt;

&lt;p&gt;Then you can register that module in web.config as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers2.gif"&gt;&lt;div style="overflow: auto;"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers2.gif" border="0"&gt;&lt;/div&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;&amp;nbsp;For Web application Projects (WAP) :&lt;/u&gt;&lt;/b&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now,when you are working with web application Project ( or VS 2003 web application ), &lt;/p&gt;

&lt;p&gt;Then you need to &lt;span style="font-weight: bold;"&gt;PrePrend &lt;/span&gt;the WebApplication Name(Actually the Root Name Space of the Project) &amp;nbsp; before the Class Name as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/WAP%20Handler%20register.jpg"&gt;&lt;/a&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers3.gif"&gt;&lt;div style="overflow: auto;"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers3.gif" style="width: 804px; height: 80px;" width="804" border="0" height="67"&gt;&lt;/div&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;u&gt;&lt;b&gt;When The module Or Handler Written in a separate Class Library:&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;when you need to register a custom HttpModule&amp;nbsp; that is written in a separate class library , then you need to use the following format :&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/custom%20class%20library%20register%20handler.jpg"&gt;&lt;/a&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers4.gif"&gt;&lt;div style="overflow: auto;"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ModulesHandlers4.gif" width="826" border="0" height="74"&gt;&lt;/div&gt;&lt;/a&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;In this Blog post i mentioned the correct way to specify the Type attributefor&amp;nbsp; Web application Project, Website project, and&amp;nbsp; Custom class library project.Failing to correctly specifying the type will causes this "Could not load file or assembly&amp;nbsp; or one of its dependencies "...&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;Hope that Helps&lt;/p&gt;

&lt;p&gt;Anas Ghanem&lt;br&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6220462" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Why The Images displayed in IE but not in FireFox ?</title><link>http://weblogs.asp.net/anasghanem/archive/2008/07/13/why-the-images-displayed-in-ie-but-not-in-firefox.aspx</link><pubDate>Sat, 12 Jul 2008 22:00:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6393976</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/07/13/why-the-images-displayed-in-ie-but-not-in-firefox.aspx#comments</comments><description>
&lt;p&gt;I noticed there is a lot of articles that is specified an incorrect images path that only works in IE , those articles used the backslash ("\") character in the Images paths , &lt;u&gt;note that using backslash in the images URL is incorrect&lt;/u&gt; ! instead we must use the slash ("/") , for example &lt;/p&gt;
&lt;p&gt;this image will not be recognized by Firefox : &lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;lt;img src='\images\left.gif'&amp;nbsp; ....&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;instead it must be&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;lt;img src='/images/left.gif'&amp;nbsp; ....&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;what about asp:Image ?&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;if you used the backslash in the asp image control , the run time will change it to slash&amp;nbsp; if and only if you used a relative image path , for example &lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;lt;asp:Image ID="Image1" runat="server" ImageUrl="~\images\left.gif" /&amp;gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;will be rendered as&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;lt;img id="Image1" src="images/left.gif" style="border-width:0px;" /&amp;gt;&lt;/b&gt;&lt;/p&gt;
&lt;pre id="line1"&gt;Of course the same rule applies when specifying the image URL in the style sheets , for example when settings the &lt;a href="http://www.w3schools.com/css/pr_background-image.asp" mce_href="http://www.w3schools.com/css/pr_background-image.asp"&gt;Background-image&lt;/a&gt; attribute ,&lt;/pre&gt;&lt;p&gt;
&lt;b&gt;background-image:url(images/left.gif); &amp;nbsp;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Hope it Helps 
&lt;/p&gt;&lt;p&gt;Anas Ghanem &lt;/p&gt;&lt;b&gt;&lt;/b&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6393976" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>you may get "System.MethodAccessException" after installing .net 3.5 and vs 2008 sp1 Beta </title><link>http://weblogs.asp.net/anasghanem/archive/2008/07/08/you-could-get-quot-system-methodaccessexception-quot-after-installing-net-3-5-and-vs-2008-sp1-beta.aspx</link><pubDate>Tue, 08 Jul 2008 09:49:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6375687</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/07/08/you-could-get-quot-system-methodaccessexception-quot-after-installing-net-3-5-and-vs-2008-sp1-beta.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;After i installed the sp1 beta for &amp;nbsp;Visual studio 2008 and .net 3.5&amp;nbsp;&amp;nbsp;i get that exception , I'm working on windows xp sp3 .&lt;/P&gt;
&lt;P mce_keep="true"&gt;I solved that by reseting All the Code Access security policies&amp;nbsp;, and then&amp;nbsp; restarted the IIS.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6375687" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Building a color selector control</title><link>http://weblogs.asp.net/anasghanem/archive/2008/06/22/building-a-color-selector-control.aspx</link><pubDate>Sun, 22 Jun 2008 08:32:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6307766</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/06/22/building-a-color-selector-control.aspx#comments</comments><description>&lt;p mce_keep="true"&gt;
&lt;/p&gt;&lt;div&gt;
&lt;p&gt;This article will show you how to create a color selector control that will looks like the image in the right side. &amp;nbsp;&lt;img src="http://i299.photobucket.com/albums/mm300/AnasGhanem/ColorsLis-thumb.gif" title="Colors Selector Image" alt="Colors Selector Image" mce_src="http://i299.photobucket.com/albums/mm300/AnasGhanem/ColorsLis-thumb.gif" width="164" align="right" height="165"&gt; &lt;/p&gt;Read the &lt;a href="http://wiki.asp.net/page.aspx/410/building-a-color-selector-control/" mce_href="http://wiki.asp.net/page.aspx/410/building-a-color-selector-control/"&gt;full article&lt;/a&gt; on ASP.Net Wiki&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;br&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6307766" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Don't forget to check "Static content service" in IIS7 installation </title><link>http://weblogs.asp.net/anasghanem/archive/2008/05/23/don-t-forget-to-check-quot-static-content-service-quot-in-iis7-installation.aspx</link><pubDate>Fri, 23 May 2008 19:31:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6214791</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/05/23/don-t-forget-to-check-quot-static-content-service-quot-in-iis7-installation.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;before a couple of days ,I started to work on Vista and IIS 7, and since the default installation for Vista doesn't includes IIS7 ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;I started by trying to&amp;nbsp; install IIS 7, I went to control panel, Programs and features, then to " turns windows features on or off",&lt;/P&gt;
&lt;P mce_keep="true"&gt;After the dialog displayed , I navigate to application development features and checked asp.net and IIS management console,&lt;/P&gt;
&lt;P mce_keep="true"&gt;then I selects to install them , after the installation finishes , I prompted to restart the computer and i did ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;after i logged in a gain , and after i added an existing website to in IIS, i requested the website from the browser,then &lt;A href="http://forums.iis.net/p/1149416/1869818.aspx" mce_href="http://forums.iis.net/p/1149416/1869818.aspx"&gt;the problems&lt;/A&gt; started ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;the browser displayed an empty page with no images , no scripts ... I tried to restart, reinstall with no , after many&amp;nbsp; hours I find it ,&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I didn't check the "Static Content service" , look at the red Box in the Image below :&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG height=286 src="http://weblogs.asp.net/blogs/anasghanem/various/IIS7%20static%20doc.jpg" width=302 mce_src="http://weblogs.asp.net/blogs/anasghanem/various/IIS7%20static%20doc.jpg"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Note that the "static content" service is responsible for serving the Static contents like images, scripts , style sheets file, ....&lt;/P&gt;
&lt;P mce_keep="true"&gt;In my opinion , if the user doesn't checked this option( which will be checked by default if you checked the " internet information service " root node&amp;nbsp; ) windows vista must displays an alert or something , so that the user&amp;nbsp; doesn't waste the time to know the problem ...&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;So I posted this problem&amp;nbsp; and hoping to help some one in the future , &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Best Regards,&lt;/P&gt;
&lt;P mce_keep="true"&gt;Anas Ghanem&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6214791" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Vista/default.aspx">Vista</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/IIS/default.aspx">IIS</category></item><item><title>Avoid using the Session in The Page Constructor OR in Page Local Variables </title><link>http://weblogs.asp.net/anasghanem/archive/2008/05/07/avoid-using-the-session-in-the-page-constructor.aspx</link><pubDate>Wed, 07 May 2008 21:50:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6166924</guid><dc:creator>anas</dc:creator><slash:comments>5</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/05/07/avoid-using-the-session-in-the-page-constructor.aspx#comments</comments><description>&lt;p&gt;While I'm helping the Folks on asp.net forums, I noticed that there is a lot of develoeprs trying to access the Http Session in Page Constructor !&lt;/p&gt;
&lt;p&gt;Most of them used this to Implement a kind of Secured Base Page&amp;nbsp; that checks the session value ,and if its missing , it will redirect to login or whatever page,&lt;/p&gt;
&lt;p&gt;some of them write this Class :&lt;/p&gt;
&lt;div style="width: 100%; background-color: rgb(238, 238, 238);"&gt;
&lt;p&gt;public class AdminSecuredPage : System.Web.UI.Page&lt;br&gt;{&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public AdminSecuredPage()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Session["AdminUser"] == null) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Redirect("~/login.aspx");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Note that the above class will throws HttpException , &lt;/p&gt;
&lt;p&gt;which tells :&lt;br&gt;&lt;/p&gt;
&lt;p&gt;"&lt;i&gt;&lt;u&gt;S&lt;/u&gt;&lt;u&gt;ession state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the &amp;lt;configuration&amp;gt; ...&lt;/u&gt;&lt;/i&gt;"&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;well the above exception will be thrown because the session is not ready when the Page constructor was called .&lt;/p&gt;
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;The Solution :&amp;nbsp;&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;One solution is to Move the Code from Page Constructor to&amp;nbsp; Page_init , Note that the page_init for this class will be called before the the Page_init of its Sub Page Class,&lt;/p&gt;
&lt;p&gt;so you can check the Session value as follows:&lt;/p&gt;
&lt;div style="width: 100%; background-color: rgb(238, 238, 238);"&gt;
&lt;p&gt;public class AdminSecuredPage : System.Web.UI.Page&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public AdminSecuredPage()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {}&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected override void OnInit(EventArgs e)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // if the user is not Admin , redirect to Login Page&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Session["AdminUser"] == null)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Redirect("~/login.aspx");&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this needed to initialize its base page class &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base.OnInit(e);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/div&gt;
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p mce_keep="true"&gt;&lt;b&gt;Edit 1:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;&lt;i&gt;Note that using the session for that purpose is not a good practice , because there is al ready a built in &lt;a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" class="" mce_href="http://msdn.microsoft.com/en-us/library/aa480476.aspx"&gt;FormsAuthentication&lt;/a&gt; services for asp.net,&lt;/i&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;&lt;i&gt;however , i will not discuss the security approches here...&lt;/i&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Edit 2:&lt;/p&gt;&lt;p&gt;I want to mention that you should also avoid accessing the Session in the Page Local Variables , like this example ( look at the Bold word)&lt;br&gt;&lt;/p&gt;&lt;p&gt;Partial Class Page1&lt;/p&gt;&lt;p&gt;Inherits System.Web.UI.Page&lt;/p&gt;
&lt;p mce_keep="true"&gt;&amp;nbsp;Private LocalVar as string=&lt;b&gt;Session("MyVar")&lt;/b&gt;&lt;/p&gt;&lt;p mce_keep="true"&gt;&lt;br&gt;that will also throw the HttpException  !&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope It Helps,&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Anas Ghanem&lt;br&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6166924" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Session/default.aspx">Session</category></item><item><title>Preventing the Deleted Users from logging to your site</title><link>http://weblogs.asp.net/anasghanem/archive/2008/04/18/preventing-the-deleted-users-from-logging-to-my-site.aspx</link><pubDate>Fri, 18 Apr 2008 22:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6111171</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/04/18/preventing-the-deleted-users-from-logging-to-my-site.aspx#comments</comments><description>
&lt;p&gt;while working with Forms Authentication and Membership services , if the user selects " remember me " check box in the login dialog ,the runtime will create a persistent authentication&amp;nbsp; cookie for him, the persisted cookie is responsible to keep the user logged in for a specified period(even he closed his browser) ,and the default period is 30 minutes in .Net 2.0 or later , and you can change it&amp;nbsp; to some value lets say 50 minutes&amp;nbsp; as follows :&lt;/p&gt;

&lt;p&gt;in web.config file&amp;nbsp; :&lt;/p&gt;

&lt;p&gt;&amp;lt;authentication mode="Forms"&amp;gt; &lt;br&gt;&amp;nbsp; &amp;lt;forms timeout="50"&amp;gt;&amp;lt;/forms&amp;gt; &lt;br&gt;&amp;lt;/authentication&amp;gt;&lt;/p&gt;

&lt;p&gt;Now the problem comes if the administrator deleted the user from the Membership users , the user still authenticated and can access your site !&lt;/p&gt;

&lt;p&gt;to override this behavior , you need to check the user existence upon request , and redirect the user to login page if he is not exists ,&lt;/p&gt;

&lt;p&gt;to accomplish this , you can use HttpModule that intercept the user request .&lt;/p&gt;

&lt;p&gt;the following are the HttpModule :&lt;/p&gt;
&lt;div style="background-color: rgb(221, 221, 221);"&gt;

&lt;p&gt;Public Class checkUser &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Implements IHttpModule &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub Dispose() Implements System.Web.IHttpModule.Dispose &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AddHandler context.AuthenticateRequest, AddressOf OnAuthenticateRequest &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sub OnAuthenticateRequest(ByVal sener As Object, ByVal e As EventArgs) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim context As HttpContext = HttpContext.Current &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim response As HttpResponse = HttpContext.Current.Response &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If context.User.Identity.AuthenticationType = "Forms" AndAlso Membership.GetUser(context.User.Identity.Name) Is Nothing Then &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthentication.SignOut() &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.RewritePath("~/login.aspx") &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If &lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub &lt;/p&gt;

&lt;p&gt;End Class&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;and you need to register it in web.config file as follows:&lt;/p&gt;

&lt;p&gt;&amp;lt;httpModules&amp;gt; &lt;br&gt;&amp;nbsp; &amp;lt;add name="checkUserStatus" type="checkUser"/&amp;gt; &lt;br&gt;&amp;lt;/httpModules&amp;gt;&lt;/p&gt;

&lt;p&gt;Of&amp;nbsp; course this solution will slow your website , because it will add one extra database call for every request ...&lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;

&lt;p&gt;Anas Ghanem&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6111171" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Security/default.aspx">Security</category></item><item><title>The Differences in Profile between Web Application Projects (WAP) and website</title><link>http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website.aspx</link><pubDate>Sat, 12 Apr 2008 20:46:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6092654</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/04/12/the-differences-in-profile-between-web-application-projects-wap-and-website.aspx#comments</comments><description>&lt;p&gt;The profile services is a very helpful and easy way to add custom properties for your users which is&amp;nbsp;&amp;nbsp;not contained in the Standard MembershipUser Properties...&lt;/p&gt;
&lt;p&gt;for example , you may need to add the Marital status , Date of Birth, Address.... all of these are custom properties that you may need them while developing your projects ...&lt;/p&gt;
&lt;p&gt;If you are familiar with Profile .. you will know that the first thing that must done when working with profiles is to set the Profile properties in web.config File ,&lt;/p&gt;
&lt;p&gt;for example ,you can add&amp;nbsp; the Date of Birth, address, Marital status for the user profile as follows,&lt;/p&gt;
&lt;p&gt;&amp;lt;profile&amp;gt; &lt;br&gt;&amp;nbsp; &amp;lt;properties &amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="DateOfBirth" type="DateTime"/&amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="Address" type="String"/&amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add name="MaritalStatus" type="String"/&amp;gt; &lt;br&gt;&amp;nbsp; &amp;lt;/properties&amp;gt; &lt;br&gt;&amp;lt;/profile&amp;gt;&lt;/p&gt;
&lt;p&gt;after saving the file , and working under a website project , &lt;/p&gt;
&lt;p&gt;you will notice that if you&amp;nbsp; typed profile in the page code behind , you will see the properties&amp;nbsp; generated for you as in the picture below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ProfileStrongType.JPG"&gt;&lt;img src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ProfileStrongType.JPG" mce_src="http://weblogs.asp.net/blogs/anasghanem/BlogPosts/ProfileStrongType.JPG" border="1"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;this happened because the Visual studio created a new class called &lt;b&gt;ProfileCommon&lt;/b&gt; Thats inherits &lt;b&gt;ProfileBase&lt;/b&gt; , and adds the new properties to it ..&lt;/p&gt;
&lt;p&gt;Note that visual studio will always update that class when you change the Profile properties in web.config ...&lt;/p&gt;
&lt;p&gt;Now , if you are working with web application projects , you will notice that adding the Profile properties to web.config will not add any properties to Profile object in the code behind of the page.... this is because Visual studio doesn't generate a &lt;b&gt;profileCommon&lt;/b&gt; class ...&lt;/p&gt;
&lt;p&gt;instead you need to access the properties using&amp;nbsp; ProfielBase.GetPropertyValue(PropertyName)&lt;/p&gt;
&lt;p&gt;for example , to access the DateOfBirth property , you need to use this code &lt;/p&gt;
&lt;p&gt;Dim DOB As DateTime = CDate(HttpContext.Current.Profile.GetPropertyValue("DateOfBirth"))&lt;/p&gt;
&lt;p&gt;In this post , I talked about the Differences in Profile&amp;nbsp; between the normal website and WAP projects&amp;nbsp; , Note that there is a lot of other differences between them, for example , &lt;/p&gt;
&lt;p&gt;when working with resource files , the website will provide a strong typing for resources properties which is also handled by Visual studio ...&lt;/p&gt;
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Anas Ghanem&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6092654" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/WAP/default.aspx">WAP</category></item><item><title>Redirecting the Users to different pages based on there roles</title><link>http://weblogs.asp.net/anasghanem/archive/2008/04/12/redirecting-the-users-to-different-pages-based-on-there-roles.aspx</link><pubDate>Sat, 12 Apr 2008 20:19:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6092606</guid><dc:creator>anas</dc:creator><slash:comments>5</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/04/12/redirecting-the-users-to-different-pages-based-on-there-roles.aspx#comments</comments><description>&lt;p&gt;while working with login control , you can redirect the users to a different pages base on there roles , to do this , you need to handle theLoggedIn event for&amp;nbsp; login control&amp;nbsp;&amp;nbsp; which is fired after the user logged in successfully ,&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Assume we have 2 roles , Admins and Editors ..&lt;/p&gt;  &lt;p&gt;and assume that every role has its own directory ,&lt;/p&gt;  &lt;p&gt;you can check the user role and&amp;nbsp; redirect the user in the loggedIn event handler of the Login control as follows:&lt;br&gt;&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;blockquote&gt;   &lt;div style="width: 100%; background-color: rgb(238, 238, 238);"&gt;     &lt;p&gt;protected void Login1_LoggedIn(object sender, EventArgs e) { &lt;/p&gt;      &lt;p&gt;if(Roles.IsUserInRole("Admins")) &lt;/p&gt;      &lt;p&gt;&amp;nbsp; Response.Redirect("~/Admins/Default.aspx"); &lt;/p&gt;      &lt;p&gt;&amp;nbsp;&amp;nbsp; else if(Roles.IsUserInRole("Editors"))&lt;/p&gt;      &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Redirect("~/Editors/Default.aspx");&lt;/p&gt;      &lt;p&gt;}&lt;/p&gt;   &lt;/div&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Regards,&lt;/p&gt;  &lt;p&gt;Anas Ghanem&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6092606" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Security/default.aspx">Security</category></item><item><title>Putting your website in a maintanance mode based on a weekly schedule </title><link>http://weblogs.asp.net/anasghanem/archive/2008/03/30/putting-your-website-in-a-maintanance-mode-based-on-a-weekly-schedule.aspx</link><pubDate>Sun, 30 Mar 2008 19:55:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6049604</guid><dc:creator>anas</dc:creator><slash:comments>7</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/03/30/putting-your-website-in-a-maintanance-mode-based-on-a-weekly-schedule.aspx#comments</comments><description>&lt;p&gt;In this blog i will talk about how to redirect the website visitors to a page that display a " web site&amp;nbsp; under maintenance"&amp;nbsp; ,&lt;/p&gt;
&lt;p&gt;you can implement this functionality in your Global application file ( &lt;a href="http://msdn2.microsoft.com/en-us/library/1xaas8a2%28VS.71%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/1xaas8a2(VS.71).aspx"&gt;Global.asax&lt;/a&gt; file) , &lt;/p&gt;
&lt;p&gt;you can use&amp;nbsp; Application_BeginRequest event handler which will be called when your website receives a new request ,&lt;/p&gt;
&lt;p&gt;this example will put your website in a maintenance mode if the current day is Saturday and for a one hour (from 10 -11) &lt;/p&gt;
&lt;p&gt;add the following function to Global.asax file ,&lt;/p&gt;
&lt;p&gt;(if you don't have this file in your website , in visual studio , right click&amp;nbsp; on the website , select add new Item , select global Application Class)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div style="width: 100%; background-color: rgb(238, 238, 238);"&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub Application_BeginRequest(ByVal source As Object, ByVal e As EventArgs)&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim application As HttpApplication = CType(source, _&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpApplication)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim context As HttpContext = application.Context&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Now.DayOfWeek = DayOfWeek.Saturday AndAlso Now.Hour = 10 Then&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.RewritePath("~/UnderMaintanace.aspx")&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/p&gt;

&lt;/div&gt;&lt;br&gt;
&lt;p&gt;&amp;nbsp;adding&amp;nbsp; the above code will redirect your website users to UnderMaintanace.aspx page if the day is Saturday and if the time between 10 -11 .&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;Note that i used &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.rewritepath%28VS.71%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.rewritepath(VS.71).aspx"&gt;RewritePath&lt;/a&gt; and not Response.redirect because the second one will make a new request to the website and so we will have infinite loop (until we redirect to an HTML page which will not handled by asp net runtime and the function will not get executed )&amp;nbsp;&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;the above solution use the date and time of the week to put the website in a maintenance mode , but you can extend this to more practical scenarios ,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;for example , you can use a settings file for your website, so that the administrator can set some flag and put the website in maintenance mode !&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Another thing you may want to do is to use http module instead of using the Global application file , so that you can have a reusable module that can be plugged&amp;nbsp; to any new website you design.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Further resources:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa479332.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa479332.aspx"&gt;Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components &lt;br&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://support.microsoft.com/kb/307996" mce_href="http://support.microsoft.com/kb/307996"&gt;How To Create an ASP.NET HTTP Module Using Visual C# .NET&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Anas Ghanem&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6049604" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Tips+and+Tricks/default.aspx">Tips and Tricks</category></item><item><title>User Profile Hive Cleanup, A service to help with slow log off and unreconciled profile problems.</title><link>http://weblogs.asp.net/anasghanem/archive/2008/03/25/user-profile-hive-cleanup-a-service-to-help-with-slow-log-off-and-unreconciled-profile-problems.aspx</link><pubDate>Tue, 25 Mar 2008 14:59:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6024164</guid><dc:creator>anas</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/03/25/user-profile-hive-cleanup-a-service-to-help-with-slow-log-off-and-unreconciled-profile-problems.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;did your windows XP take a long time to loggoff ? My windows was taking more that a minute to logoff the user ,it just show me logging off , but the computer is Idle...&lt;/P&gt;
&lt;P mce_keep="true"&gt;this happened because there maybe a handle to a registry key that prevent the windows from saving and clearing handle.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I was solving this problem by creating a new user account... &lt;/P&gt;
&lt;P mce_keep="true"&gt;of course this is not a practical solution , so i searched the interenet andfound that tool,&lt;/P&gt;
&lt;P mce_keep="true"&gt;And i just want to share it with you ...&lt;/P&gt;
&lt;P mce_keep="true"&gt;you can download it &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1B286E6D-8912-4E18-B570-42470E2F3582&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1B286E6D-8912-4E18-B570-42470E2F3582&amp;amp;displaylang=en"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Regards,&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6024164" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Windows+XP/default.aspx">Windows XP</category></item><item><title>Canceling Linkbutton Clicked Event when the User tries to click it Again</title><link>http://weblogs.asp.net/anasghanem/archive/2008/03/09/canceling-linkbutton-clicked-event-when-the-user-tries-to-click-it-again.aspx</link><pubDate>Sun, 09 Mar 2008 16:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5940857</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/03/09/canceling-linkbutton-clicked-event-when-the-user-tries-to-click-it-again.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;There is&amp;nbsp;many reasons to prevent that , like preventing mutiple Database Calls , Or Even Preventing them from submitting the form twice and so save the bandwidth and&amp;nbsp;server resources .&lt;/P&gt;
&lt;P mce_keep="true"&gt;this is a one solution for that Issue ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;Use a hiddenField control to remeber the Click counts ,and when the Linkbutton clicked you check to see&amp;nbsp;if the click counts &amp;gt;0 ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;if yes then you will cancel the click event ,&lt;/P&gt;
&lt;P mce_keep="true"&gt;To Accomplish this , Add a hiddenField Server control to your page as follows :&lt;/P&gt;&lt;PRE class=coloredcode&gt;&amp;lt;&lt;SPAN class=tag&gt;asp:HiddenField&lt;/SPAN&gt;&lt;SPAN class=attr&gt; ID=&lt;/SPAN&gt;&lt;SPAN class=attrv&gt;"HiddenField1"&lt;/SPAN&gt;&lt;SPAN class=attr&gt; runat=&lt;/SPAN&gt;&lt;SPAN class=attrv&gt;"server"&lt;/SPAN&gt;&lt;SPAN class=attr&gt; Value=&lt;/SPAN&gt;&lt;SPAN class=attrv&gt;"0"&lt;/SPAN&gt; /&amp;gt;&lt;/PRE&gt;&lt;PRE class=coloredcode&gt;Now Register Onclick Attribute for the Linkbutton , in page load add this code :&lt;FONT size=2&gt;
&lt;/PRE&gt;&lt;PRE&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt; If&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Not&lt;/FONT&gt;&lt;FONT size=2&gt; IsPostBack &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/FONT&gt;&lt;FONT size=2&gt;
   LinkButton1.Attributes(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"onclick"&lt;/FONT&gt;&lt;FONT size=2&gt;) = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;.Format(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"javascript:var Count = document.getElementById('{0}');&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT color=#a31515 size=2&gt; if (Count.value&amp;gt;0) return false ;Count.value =Count.value+1; "&lt;/FONT&gt;&lt;FONT size=2&gt;, HiddenField1.ClientID)&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt; End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;&lt;U&gt;&lt;STRONG&gt;How To Test that :&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;BR&gt;&lt;/STRONG&gt;&lt;/U&gt;Add the hidden field and register the Onclick attribute as mentioned , &lt;BR&gt;Now click the LinkButton for the first time , the form must be submitted (postback must occured) &lt;BR&gt;Try to click the LinkButton for the second time, you will notice that there is no postback happened . &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Regards, &lt;BR&gt;Anas ghanem&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5940857" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Tip/ Trick: Preventing Session Loss when using Cookieless sessions with  TreeView and Menu controls</title><link>http://weblogs.asp.net/anasghanem/archive/2008/03/08/tip-trick-preventing-session-loss-when-using-cookieless-sessions-with-treeview-and-menu-controls.aspx</link><pubDate>Sat, 08 Mar 2008 21:16:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5939756</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/03/08/tip-trick-preventing-session-loss-when-using-cookieless-sessions-with-treeview-and-menu-controls.aspx#comments</comments><description>&lt;P&gt;By default .net runtime uses the cookies to remember the session Id between the requests ,&lt;BR __designer:dtid="16607045100765187"&gt;but when using Cookie less sessions ,the runtime inserts the Session Id to the requested url &amp;nbsp;,&lt;BR __designer:dtid="16607045100765188"&gt;this way the runtime can remember the session id and prevent the session loss .&lt;BR __designer:dtid="16607045100765189"&gt;&lt;BR __designer:dtid="16607045100765190"&gt;The problem is , when using the Menu and TreeView Controls , these controls doesn't handle this issue ,&lt;BR __designer:dtid="16607045100765191"&gt;so when those controls display there data from the Site maps, they didn't append the session id to the Navigation Urls of there Items ,&lt;BR __designer:dtid="16607045100765192"&gt;and so when the User Navigate to a page using those controls , he will redirected to a Url that didn't contains the session Id,&lt;BR __designer:dtid="16607045100765193"&gt;and so the runtime can't extract the session id , Hence the session will be &amp;nbsp;lost .&lt;BR __designer:dtid="16607045100765194"&gt;&lt;BR __designer:dtid="16607045100765195"&gt;&lt;B&gt;The Solution:&lt;/B&gt;&lt;BR __designer:dtid="16607045100765196"&gt;the solution&amp;nbsp; is to Manually Append the Session Id to NavigateUrl &amp;nbsp;of the Items for those Navigation controls,&lt;BR __designer:dtid="16607045100765197"&gt;we can use &lt;A href="http://msdn2.microsoft.com/en-us/library/system.web.httpresponse.applyapppathmodifier%28VS.71%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.web.httpresponse.applyapppathmodifier(VS.71).aspx"&gt;HttpContext.Current.Response.ApplyAppPathModifier&lt;/A&gt; to modify the Item Urls as Follows:&lt;BR __designer:dtid="16607045100765198"&gt;&lt;BR __designer:dtid="16607045100765199"&gt;For the Menu Control , we can use MenuItemDataBound Event Handler to accomplish this ,&lt;BR __designer:dtid="16607045100765200"&gt;&lt;BR __designer:dtid="16607045100765201"&gt;&lt;/P&gt;
&lt;DIV style="WIDTH: 100%; BACKGROUND-COLOR: rgb(204,204,204)" __designer:dtid="16607045100765202"&gt;&amp;nbsp; protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e) &lt;BR __designer:dtid="16607045100765203"&gt;&amp;nbsp;{ &lt;BR __designer:dtid="16607045100765204"&gt;&amp;nbsp;&amp;nbsp; // appened the SessionId to Menu Item URL to Avoid sessin loss &lt;BR __designer:dtid="16607045100765205"&gt;&amp;nbsp; &amp;nbsp;e.Item.NavigateUrl = HttpContext.Current.Response.ApplyAppPathModifier(e.Item.NavigateUrl); &lt;BR __designer:dtid="16607045100765206"&gt;&amp;nbsp;}&lt;BR __designer:dtid="16607045100765207"&gt;&lt;/DIV&gt;&lt;BR __designer:dtid="16607045100765208"&gt;&amp;nbsp;For the TreeView Control, we can use TreeNodeDataBound&amp;nbsp; to accomplish this&lt;BR __designer:dtid="16607045100765209"&gt;&lt;BR __designer:dtid="16607045100765210"&gt;
&lt;DIV style="WIDTH: 100%; BACKGROUND-COLOR: rgb(204,204,204)" __designer:dtid="16607045100765211"&gt;&lt;BR __designer:dtid="16607045100765212"&gt;protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e) &lt;BR __designer:dtid="16607045100765213"&gt;&amp;nbsp; { &lt;BR __designer:dtid="16607045100765214"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;e.Node.NavigateUrl = HttpContext.Current.Response.ApplyAppPathModifier(e.Node.NavigateUrl); &lt;BR __designer:dtid="16607045100765215"&gt;&amp;nbsp; }&lt;BR __designer:dtid="16607045100765216"&gt;&lt;/DIV&gt;&lt;BR __designer:dtid="16607045100765217"&gt;&amp;nbsp;Regards, 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5939756" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Session/default.aspx">Session</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Tips+and+Tricks/default.aspx">Tips and Tricks</category></item><item><title>How To Prevent the Page from using its Output Cache Based On Some Condition</title><link>http://weblogs.asp.net/anasghanem/archive/2008/03/08/how-to-programaticly-deteremine-to-use-or-not-the-page-output-cache.aspx</link><pubDate>Sat, 08 Mar 2008 17:36:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5939406</guid><dc:creator>anas</dc:creator><slash:comments>2</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/03/08/how-to-programaticly-deteremine-to-use-or-not-the-page-output-cache.aspx#comments</comments><description>&lt;DIV&gt;
&lt;P&gt;Some times you may have a page with output cache enabled , and for some reason you don't want to use its output cache , &lt;/P&gt;
&lt;P&gt;Take this seanrio:&lt;/P&gt;
&lt;P&gt;you have a page that displays a Dynamic data , and you have 2 users &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Viewers: they just View your page.&lt;/LI&gt;
&lt;LI&gt;Editors: they need to Edit the data in the page , and they must see the latest changes they did .&lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;and you decided to Enable output Caching on the page to enhance the Performance&amp;nbsp; , &lt;/P&gt;
&lt;P&gt;Now the problem is : the Editors can't Edit and See the Latest chages they did , because the page output is cached ,&lt;/P&gt;
&lt;P&gt;you need to enforce the page to show and render the latest data without using its current cached output,and without affecting the current cached output.&lt;/P&gt;
&lt;P&gt;The solution :&lt;/P&gt;
&lt;P&gt;you need to use &lt;A href="http://msdn2.microsoft.com/en-us/library/system.web.httpcachepolicy.addvalidationcallback%28VS.71%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.web.httpcachepolicy.addvalidationcallback(VS.71).aspx"&gt;HttpCachePolicy.AddValidationCallback Method&lt;/A&gt; , so that you can register an output Cache&amp;nbsp; validation Callback ,&lt;/P&gt;
&lt;P&gt;Set the Output Caching for your page By setting the output cache in ASPX code as &amp;nbsp;follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;%@ OutputCache VaryByParam="none" Duration="600" %&amp;gt;&lt;/P&gt;
&lt;P&gt;and in Code behind :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Page_Load:&lt;/P&gt;
&lt;DIV style="WIDTH: 100%; BACKGROUND-COLOR: rgb(204,204,204)"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If HttpContext.Current.User.Identity.IsAuthenticated Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Cache.AddValidationCallback(New HttpCacheValidateHandler(AddressOf ValidateCache), Nothing)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/P&gt;&lt;/DIV&gt;&lt;BR&gt;And the ValidateCache method:&lt;BR&gt;
&lt;DIV style="WIDTH: 100%; BACKGROUND-COLOR: rgb(204,204,204)"&gt;&lt;BR&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '' this method will invoked every time the page requested &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Shared Sub ValidateCache(ByVal Currentcontext As HttpContext, ByVal data As Object, ByRef status As HttpValidationStatus)&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Currentcontext.User.IsInRole("Editors") Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Dont use the output cache for the Editors&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' and force the page to Excute ( handled as a cache miss)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; status = HttpValidationStatus.IgnoreThisRequest&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' nothing needed , just use the Output cache &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' also if you want to Invalidate the page Output cache , &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' you need to set the status value to&amp;nbsp; HttpValidationStatus.Invalid&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub &lt;/P&gt;&lt;/DIV&gt;&lt;BR&gt;
&lt;P&gt;How to Test :&lt;/P&gt;
&lt;P&gt;Add a break point on the Page_laod event Handler, Page_Load will not called for Non Editors Users (Unless the output Cache Expired )&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Hope it Helps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anas Ghanem&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5939406" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/Caching/default.aspx">Caching</category></item><item><title>A list of some basic ASP.NET interview questions</title><link>http://weblogs.asp.net/anasghanem/archive/2008/02/22/common-net-technical-questions-that-you-will-be-asked-about-in-the-interviews.aspx</link><pubDate>Fri, 22 Feb 2008 00:41:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5837604</guid><dc:creator>anas</dc:creator><slash:comments>8</slash:comments><comments>http://weblogs.asp.net/anasghanem/archive/2008/02/22/common-net-technical-questions-that-you-will-be-asked-about-in-the-interviews.aspx#comments</comments><description>&lt;span style="display: block;" class="ACECollapsed" border="0" id="divExpCollAsst_39"&gt;&lt;font face="Arial"&gt;the following are a list of some basic ASP.NET interview questions :&lt;/font&gt;&lt;br&gt;&lt;br&gt;
&lt;font face="Arial"&gt;1.&amp;nbsp;Explain the life cycle of an ASP .NET page. &lt;br&gt;
2.&amp;nbsp;Explain the .NET architecture. &lt;br&gt;
3.&amp;nbsp;What are object-oriented concepts? &lt;br&gt;
4.&amp;nbsp;How do you create multiple inheritance in c# and .NET? &lt;br&gt;
5.&amp;nbsp;When is web.config called? &lt;br&gt;
6.&amp;nbsp;Differences between DLL and EXE? &lt;br&gt;
7.&amp;nbsp;Can an assembly have EXE? &lt;br&gt;
8.&amp;nbsp;Can a DLL be changed to an EXE? &lt;br&gt;
9.&amp;nbsp;Compare &amp;amp; contrast rich client (smart clients or Windows-based) &amp;amp; browser-based Web application &lt;br&gt;
10.&amp;nbsp;Compare Client server application with n-Tier application &lt;br&gt;
11.&amp;nbsp;Can a try block have more than one catch block? &lt;br&gt;
12.&amp;nbsp;Can a try block have nested try blocks? &lt;br&gt;
13.&amp;nbsp;How do you load an assembly at runtime? &lt;br&gt;
14.&amp;nbsp;If I am writing in a language like VB or C++, what are the procedures to be followed to support .NET? &lt;br&gt;
15.&amp;nbsp;How do you view the methods and members of a DLL? &lt;br&gt;
16.&amp;nbsp;What is shadowing? &lt;br&gt;
17.&amp;nbsp;What are the collections you’ve used? &lt;br&gt;
18.&amp;nbsp;What is a static class? &lt;br&gt;
19.&amp;nbsp;What is static member? &lt;br&gt;
20.&amp;nbsp;What is static function? &lt;br&gt;
21.&amp;nbsp;What is static constructor? &lt;br&gt;
22.&amp;nbsp;How can we inherit a static variable? &lt;br&gt;
23.&amp;nbsp;How can we inherit a static member? &lt;br&gt;
24.&amp;nbsp;Can we use a static function with a non-static variable? &lt;br&gt;
25.&amp;nbsp;How can we access static variable? &lt;br&gt;
26.&amp;nbsp;Why main function is static? &lt;br&gt;
27.&amp;nbsp;What is garbage collection?&lt;br&gt;
28.&amp;nbsp;Can we force garbage collector to run?&lt;br&gt;
29.&amp;nbsp;What is reflection?&lt;br&gt;
30.&amp;nbsp;What are different type of JIT?&lt;br&gt;
31.&amp;nbsp;What are Value types and Reference types?&lt;br&gt;
32.&amp;nbsp;What is concept of Boxing and Unboxing?&lt;br&gt;
33.&amp;nbsp;What’s difference between VB.NET and C#?&lt;br&gt;
34.&amp;nbsp;What’s difference between System exceptions and Application exceptions?&lt;br&gt;
35.&amp;nbsp;What is CODE Access security?&lt;br&gt;
36.&amp;nbsp;What is a satellite assembly?&lt;br&gt;
37.&amp;nbsp;How to prevent my .NET DLL to be decompiled?&lt;br&gt;
38.&amp;nbsp;What’s the difference between Convert.toString and .toString() method ?&lt;br&gt;
39.&amp;nbsp;What is Native Image Generator (Ngen.exe)?&lt;br&gt;
We have two version of the same assembly in GAC? I want my client to make choice which assembly to choose?&lt;br&gt;
40.&amp;nbsp;What is CodeDom?&lt;/font&gt;&lt;br&gt;&lt;br&gt;
&lt;font face="Arial"&gt;The questions above are some of the many questions
the employer may pose on you during an interview. Sometimes questions
will be divided into sections. So, for example, there may be a section
on Threading and you would have to answer a series of questions under
that. Some other popular sections would be Remoting and Webservices,
caching concepts, OOPS, ASP.NET, .NET Architecture, ADO.NET, SQL
Server, UML, XML.&lt;br&gt;
Hope this helps you prepare! Good luck!&lt;/font&gt;&lt;/span&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5837604" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/anasghanem/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/anasghanem/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>