<p>When I am working with ASP.NET, I find that there are always unexpected things I run into that take forever to debug. I figure that having a consolidated list of these would be great for those "weird error" circumstances, plus to expand our knowledge of oddness in the platform.</p>

<p>So: answer with one of your "Gotcha"s!</p>

<p>I'll start:
Under ASP.NET (VB), performing a Response.Redirect inside a try/catch block does not stop execution of the current Response, which can lead to two concurrent Responses executing against the same Session.</p>

[{'answer_id': 66285, 'author': 'Bob Dizzle', 'author_id': 9581, 'author_profile': 'https://Stackoverflow.com/users/9581', 'pm_score': 3, 'selected': False, 'text': '<p>Life cycle of custom controls does not match up perfectly with page life cycle events of same name.</p>\n'}, {'answer_id': 66295, 'author': 'Bob Dizzle', 'author_id': 9581, 'author_profile': 'https://Stackoverflow.com/users/9581', 'pm_score': 4, 'selected': False, 'text': "<p>Don't dynamically add controls after the page init event as it will screw up the viewstate tree.</p>\n"}, {'answer_id': 66311, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 2, 'selected': False, 'text': "<p>Don't edit your web.config with notepad if you have accented characters, it will replace it with one with the wrong encoding. It will look the same though. Just your application will not run.</p>\n"}, {'answer_id': 66313, 'author': 'mattruma', 'author_id': 1768, 'author_profile': 'https://Stackoverflow.com/users/1768', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Viewstate</strong> ... if you are using it ... can get out of control if you are not paying attention to it.</p>\n'}, {'answer_id': 66353, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>You can't reference anything at all above the application's root folder.</p>\n"}, {'answer_id': 66357, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>All the code I have to maintain that still looks like it was written in vb6, showing complete ignorance of the newer styles.</p>\n\n<p>I'm talking things like CreateObject(), excessive &lt;% %> blocks, And/Or instead of AndAlso/OrElse, Len() instead of .Length(), s/o Hungarian prefix warts, Dim MyVariable with no type, functions with no return type... I could go on.</p>\n"}, {'answer_id': 66383, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 1, 'selected': False, 'text': '<p>Custom controls are only supported by the designer when building the control <strong>or</strong> when  building the page that uses the control, but not both.</p>\n'}, {'answer_id': 66395, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': "<p>Having to jump through hoops to get the .ClientID property into javascript.</p>\n\n<p>It'd be nice if the render phase of the lifecycle created a script that set up a var for each server control with the same name as the control that was automatically initialized to the clientID value.  Or maybe have some way to easily trigger this action.</p>\n\n<p>Hmm... I bet I could set up a method for this on my own via reflection.</p>\n"}, {'answer_id': 66401, 'author': 'Thunder3', 'author_id': 2832, 'author_profile': 'https://Stackoverflow.com/users/2832', 'pm_score': -1, 'selected': False, 'text': "<p>(VB.NET) If you send an Object via a Property's Get accessor into a function with a ByRef keyword, it will actually attempt to update the object using the Set accessor for the Property.</p>\n\n<p>Ex:</p>\n\n<p><code>UpdateName(ByRef aName as String)</code></p>\n\n<p><code>UpdateName(Employee.Name)</code> will attempt to update the name by using the Set on the Name property of Employee.</p>\n"}, {'answer_id': 67012, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 3, 'selected': False, 'text': "<p>The whole life-cycle thing in general.</p>\n\n<p>Not that I see anything wrong with it, it's just that you'd be amazed at the number of people who start working on large ASP.Net projects <em>before</em> understanding it, rather than vice versa.  Hence, it becomes a gotcha.</p>\n\n<p>Note that I said <em>large</em> projects: I think the best way to come to terms with the life cycle is to work on a few smaller projects yourself first, where it doesn't matter so much if you screw them up.</p>\n"}, {'answer_id': 72592, 'author': 'Adam Pope', 'author_id': 12226, 'author_profile': 'https://Stackoverflow.com/users/12226', 'pm_score': 1, 'selected': False, 'text': '<p>When using a gridview without a datasource control (i.e. binding a dataset straight to the control) you need to manually implement sorting and paging events as shown here:</p>\n\n<p><a href="http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/" rel="nofollow noreferrer">http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/</a></p>\n'}, {'answer_id': 179298, 'author': 'Adam Lassek', 'author_id': 1249, 'author_profile': 'https://Stackoverflow.com/users/1249', 'pm_score': 2, 'selected': False, 'text': '<p>I just learned this today: the Bind() method, as used with GridViews and ListViews, doesn\'t exist. It\'s actually hiding some Reflector magic that turns it into an Eval() and some kind of variable assignment.</p>\n\n<p>The upshot of this is that calls like:</p>\n\n<pre><code>&lt;%# FormatNameHelper(Bind("Name")) %&gt;\n</code></pre>\n\n<p>that look perfectly valid will fail. See <a href="http://weblogs.asp.net/leftslipper/archive/2007/06/29/how-asp-net-databinding-deals-with-eval-and-bind-statements.aspx" rel="nofollow noreferrer">this blog post</a> for more details.</p>\n'}, {'answer_id': 179351, 'author': 'Dan Goldstein', 'author_id': 23427, 'author_profile': 'https://Stackoverflow.com/users/23427', 'pm_score': 3, 'selected': False, 'text': "<p>Page_Load is run before control handlers. So you can't make changes in an event handler and then use those changes in the page load. This becomes an issue when you have controls in a master page (such as a login control). You can get around the issue by redirecting, but it's definitely a gotcha.</p>\n"}, {'answer_id': 1404000, 'author': 'Shaul Behr', 'author_id': 7850, 'author_profile': 'https://Stackoverflow.com/users/7850', 'pm_score': 1, 'selected': False, 'text': '<p>Linq:  If you are using Linq-To-SQL, you call <code>SubmitChanges()</code> on the data context and it throws an exception (e.g. duplicate key or other constraint violation), the offending object values remain in your memory while you are debugging, and will be resubmitted every time you subsequently call <code>SubmitChanges()</code>.</p>\n\n<p>Now here\'s the <strong>real</strong> kicker: the bad values will remain in memory <strong>even if you push the "stop" button in your IDE and restart!</strong>  I don\'t understand why anyone thought this was a good idea - but that little ASP.NET icon that pops up in your system tray stays running, and it appears to save your object cache.  If you want to flush your memory space, you have to right-click that icon and forcibly shut it down!  GOTCHA!</p>\n'}, {'answer_id': 1405123, 'author': 'Alexandre Brisebois', 'author_id': 18619, 'author_profile': 'https://Stackoverflow.com/users/18619', 'pm_score': 2, 'selected': False, 'text': '<p>If you are running Classic ASP applications in the same Virtual Directory as you ASP.Net application, the fist hit on the application must be on an ASP.Net page. This will ensure that the AppPool be built with the right context configurations. If the first page to be hit is a Classic ASP page, the results may vary from application to application. In general the AppPool is configured to use the latest framework.</p>\n'}, {'answer_id': 1820967, 'author': 'vdboor', 'author_id': 146289, 'author_profile': 'https://Stackoverflow.com/users/146289', 'pm_score': 2, 'selected': False, 'text': '<p>Making a repeater-like control, and not knowing about <code>INamingContainer</code>.</p>\n'}, {'answer_id': 1926541, 'author': 'eulerfx', 'author_id': 13855, 'author_profile': 'https://Stackoverflow.com/users/13855', 'pm_score': 0, 'selected': False, 'text': '<p>Being unaware of heaps of existing and extensible functionality in the framework. Things often redone are membership, roles, authorization, site maps. Then there are the controls and the associated tags which can be customized to alleviate issues with the client IDs among others. Also simple things like not knowing to properly use the .config file to auto import namespaces into templates, and being able to do that on a directory basis. Less known things like tag expressions can be valuable at times as well. Surely, as with all frameworks, there is a learning curve and always something left to be desired, however more often than not it is better to customize and extend an existing framework instead of rolling your own. </p>\n'}, {'answer_id': 2146687, 'author': 'oldbrazil', 'author_id': 205152, 'author_profile': 'https://Stackoverflow.com/users/205152', 'pm_score': 2, 'selected': False, 'text': '<p>Debugging is a very cool feature of ASP.Net, but as soon as you change some code in the app_code folder, you trigger a re-build of the application, leading to all sessions being lost. </p>\n\n<p>This can get very annoying while debugging a website, but you can easily prevent this using the "<strong>StateServer mode</strong>" : it\'s just a service to start and a line to change in the web.config :\nrefer to msdn : <a href="http://msdn.microsoft.com/en-us/library/ms178586.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms178586.aspx</a></p>\n\n<ol>\n<li><strong>InProc mode</strong>, which stores session state in memory on the Web server. <em>This is the default</em>.</li>\n<li><strong>StateServer mode</strong>, which stores session state in a separate process called the ASP.NET state <strong>service</strong>. This ensures that <strong>session state is preserved</strong> if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.</li>\n<li>SQL Server ...</li>\n<li>Custom ...</li>\n<li>Off!</li>\n</ol>\n'}, {'answer_id': 5110350, 'author': 'rlb.usa', 'author_id': 449902, 'author_profile': 'https://Stackoverflow.com/users/449902', 'pm_score': 2, 'selected': False, 'text': '<ul>\n<li><p>You have to worry about <a href="http://justgeeks.blogspot.com/2008/07/aspnet-session-timeouts.html" rel="nofollow">session timeouts</a> for applications where the user might take a long time.</p></li>\n<li><p>You also have to worry about <a href="http://aspnetresources.com/articles/dark_side_of_file_uploads" rel="nofollow">uploading timeouts</a> for large applications, too</p></li>\n<li><p>Validatiors may not always scroll your page to the scene of the data entry error (so the user may not ever see it and will only wonder why the submit button won\'t work ) </p></li>\n<li><p>If the user enters HTML symbols such as <code>&lt;</code>, <code>&gt;</code> (for example, <code>P &gt; 3.14</code> ), or an inadvertant <code>&lt;br&gt;</code> from copy-pasting on another page, <a href="http://www.geekpedia.com/KB99_A-potentially-dangerous-Request.Form-value-was-detected-from-the-client.html" rel="nofollow">ASP.NET will reject the page</a> and display a error.</p></li>\n<li><p><code>null.ToString()</code> produces a big fat error. Check carefully.</p></li>\n<li><p><a href="http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net/11527/ASP-and-ASP-NET-session-pool" rel="nofollow">Session pool sharing</a> across multiple applications is a disaster silently waiting to happen</p></li>\n<li><p>Moving applications around on machines with different environments is a migraine that involves <code>web.config</code> and many potential hours of google</p></li>\n<li><p>ASP.NET and MySQL are prone to caching problems if you use stored procedures</p></li>\n<li><p>AJAX can make a mess, too:</p>\n\n<ul>\n<li>There are situations where the client can bypass page validation (especially by pressing ENTER instead of pressing the submit button). You can fix it by calling <code>if(! Page.IsValid) { return ; }</code></li>\n<li>ASP buttons usually don\'t work correctly inside of UpdatePanels</li>\n<li>The more content in your UpdatePanel, the more data is asynchronously transmitted, so the longer it takes to load</li>\n<li>If your AJAX panel has a problem or error of some kind, it "locks up" and doesn\'t respond to events inside it anymore</li>\n</ul></li>\n</ul>\n'}, {'answer_id': 6615958, 'author': 'elbillaf', 'author_id': 469476, 'author_profile': 'https://Stackoverflow.com/users/469476', 'pm_score': 0, 'selected': False, 'text': '<p>Not a pure ASP.NET thing, but ...</p>\n\n<p>I was trying to use either a) nested SELECT or b) WITH clause and just could not get it to work, but people who were obviously more knowledgeable (including someone I work with) told me the syntax was fine.  TURNS OUT ...</p>\n\n<p>Was not able to use either of those with OLEDB. </p>\n\n<p><a href="https://stackoverflow.com/questions/6552035/oledb-query-to-sql-server-fails">OLEDB query to SQL Server fails</a></p>\n\n<p>(Also, I was bit by the response.redirect() in the try ... catch \'feature\' mentioned in the OP!  Great thread!)</p>\n'}, {'answer_id': 8701147, 'author': 'Björn Lindqvist', 'author_id': 189247, 'author_profile': 'https://Stackoverflow.com/users/189247', 'pm_score': 0, 'selected': False, 'text': '<p>Databound controls inside an INamingContainer control must not be placed inside templated controls such as FormView. See <a href="http://ajaxcontroltoolkit.codeplex.com/workitem/8049" rel="nofollow noreferrer">this bug report</a> for an example. Since INamingContainer controls creates their own namespace for their contained controls, two-way databinding using Bind() will not work properly. But when loading the values everything will look fine (because it is done with Eval()) it is not before you try to post back the values that they will mysteriously seem to not land in the database.</p>\n\n<p>This so question demonstrates the issue well: <a href="https://stackoverflow.com/questions/969784/ajax-tabcontainer-inside-formview-not-inserting-values">AJAX Tabcontainer inside formview not inserting values</a></p>\n'}]
['https://Stackoverflow.com/questions/66117', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2832/']