<blockquote>
  <p>This question exists because it has
  historical significance, but it is not
  considered a good, on-topic question
  for this site, <strong>so please do not use it
  as evidence that you can ask similar
   questions here.</strong></p>
  
  <p>More info: <a href="https://stackoverflow.com/faq">https://stackoverflow.com/faq</a></p>
</blockquote>

<hr>

<p>There are always features that would be useful in fringe scenarios, but for that very reason most people don't know them. I am asking for features that are not typically taught by the text books.</p>

<p>What are the ones that you know?</p>

[{'answer_id': 54931, 'author': 'GEOCHET', 'author_id': 5640, 'author_profile': 'https://Stackoverflow.com/users/5640', 'pm_score': -1, 'selected': False, 'text': '<p>This seems like a huge, vague question... \nBut I will throw in Reflection, as it has allowed me to do some incredibly powerful things like pluggable DALs and such.</p>\n'}, {'answer_id': 54932, 'author': 'Allain Lalonde', 'author_id': 2443, 'author_profile': 'https://Stackoverflow.com/users/2443', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms227673.aspx" rel="nofollow noreferrer">HttpModules</a>. The architecture is crazy elegant.  Maybe not a hidden feature, but cool none the less.</p>\n'}, {'answer_id': 54937, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 6, 'selected': False, 'text': '<p>HttpContext.Items as a request-level caching tool</p>\n'}, {'answer_id': 54962, 'author': 'Kilhoffer', 'author_id': 5469, 'author_profile': 'https://Stackoverflow.com/users/5469', 'pm_score': 4, 'selected': False, 'text': '<p>HttpContext.IsCustomErrorEnabled is a cool feature.I\'ve found it useful more than once. Here is a <a href="http://weblogs.asp.net/leftslipper/archive/2008/07/13/httpcontext-iscustomerrorenabled-one-of-asp-net-s-hidden-gems.aspx" rel="nofollow noreferrer">short post</a> about it.</p>\n'}, {'answer_id': 55112, 'author': 'Radu094', 'author_id': 3263, 'author_profile': 'https://Stackoverflow.com/users/3263', 'pm_score': 6, 'selected': False, 'text': '<p>Two things stand out in my head:</p>\n\n<p>1) You can turn Trace on and off from the code:</p>\n\n<pre><code>#ifdef DEBUG \n   if (Context.Request.QueryString["DoTrace"] == "true")\n                {\n                    Trace.IsEnabled = true;\n                    Trace.Write("Application:TraceStarted");\n                }\n#endif\n</code></pre>\n\n<p>2) You can build multiple .aspx pages using only one shared "code-behind" file.</p>\n\n<p>Build one class .cs file :</p>\n\n<pre><code>public class Class1:System.Web.UI.Page\n    {\n        public TextBox tbLogin;\n\n        protected void Page_Load(object sender, EventArgs e)\n        {\n\n          if (tbLogin!=null)\n            tbLogin.Text = "Hello World";\n        }\n    }\n</code></pre>\n\n<p>and then you can have any number of .aspx pages (after you delete .designer.cs and .cs code-behind that VS has generated) : </p>\n\n<pre><code>  &lt;%@ Page Language="C#"  AutoEventWireup="true"  Inherits="Namespace.Class1" %&gt;\n     &lt;form id="form1" runat="server"&gt;\n     &lt;div&gt;\n     &lt;asp:TextBox  ID="tbLogin" runat="server"&gt;&lt;/asp: TextBox  &gt;\n     &lt;/div&gt;\n     &lt;/form&gt;\n</code></pre>\n\n<p>You can have controls in the ASPX that do not appear in Class1, and vice-versa, but you need to remeber to check your controls for nulls.</p>\n'}, {'answer_id': 55176, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 6, 'selected': False, 'text': '<p>You can use:</p>\n\n<pre><code> Request.Params[Control.UniqueId] \n</code></pre>\n\n<p>To get the value of a control BEFORE viewstate is initialized (Control.Text etc will be empty at this point).</p>\n\n<p>This is useful for code in Init.</p>\n'}, {'answer_id': 55195, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 6, 'selected': False, 'text': '<ul>\n<li><p><strong>HttpContext.Current</strong> will always give you access to the current context\'s Request/Response/etc., even when you don\'t have access to the Page\'s properties (e.g., from a loosely-coupled helper class).</p></li>\n<li><p>You can continue executing code on the same page after redirecting the user to another one by calling <strong>Response.Redirect(<em>url</em>,</strong> false <strong>)</strong></p></li>\n<li><p>You don\'t need <em>.ASPX</em> files if all you want is a compiled <strong>Page</strong> (or any <strong>IHttpHandler</strong>). Just set the path and HTTP methods to point to the class in the <a href="http://msdn.microsoft.com/en-us/library/aa903367%28VS.71%29.aspx" rel="nofollow noreferrer"><em><code>&lt;httpHandlers&gt;</code></em> element</a> in the web.config file.</p></li>\n<li><p>A <strong>Page</strong> object can be retrieved from an <em>.ASPX</em> file programmatically by calling <strong>PageParser.GetCompiledPageInstance(virtualPath,aspxFileName,Context)</strong></p></li>\n</ul>\n'}, {'answer_id': 55229, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 7, 'selected': False, 'text': '<pre><code>throw new HttpException(404, "Article not found");\n</code></pre>\n\n<p>This will be caught by ASP.NET which will return the customErrors page. Learned about this one in a <a href="http://dotnettipoftheday.org/tips/how-to-respond-with-code-404-not-found-in-aspnet.aspx?discussion=1" rel="nofollow noreferrer">recent .NET Tip of the Day Post</a></p>\n'}, {'answer_id': 55259, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 4, 'selected': False, 'text': "<p>By default, any content between tags for a custom control is added as a child control. This can be intercepted in an <strong>AddParsedSubObject()</strong> override for filtering or additional parsing (e.g., of text content in LiteralControls):</p>\n\n<pre><code>    protected override void AddParsedSubObject(object obj)\n     { var literal = obj as LiteralControl;\n       if (literal != null) Controls.Add(parseControl(literal.Text));\n       else base.AddParsedSubObject(obj);\n     }\n</code></pre>\n\n<p>...</p>\n\n<pre><code>   &lt;uc:MyControl runat='server'&gt;\n     ...this text is parsed as a LiteralControl...\n  &lt;/uc:MyControl&gt;\n</code></pre>\n"}, {'answer_id': 55310, 'author': 'Troy DeMonbreun', 'author_id': 5487, 'author_profile': 'https://Stackoverflow.com/users/5487', 'pm_score': 8, 'selected': False, 'text': '<p>If you place a file named <strong><em>app_offline.htm</em></strong>\nin the root of a web application directory, ASP.NET 2.0+ will shut-down the application and stop normal processing any new incoming requests for that application, showing only the contents of the app_offline.htm file <em>for all new requests</em>.</p>\n\n<p>This is the quickest and easiest way to display your "Site Temporarily Unavailable" notice while re-deploying (or rolling back) changes to a Production server.</p>\n\n<p>Also, as pointed out by <a href="https://stackoverflow.com/users/1659/marxidad">marxidad</a>, make sure you have at least 512 bytes of content within the file so IE6 will render it correctly.</p>\n'}, {'answer_id': 55316, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 4, 'selected': False, 'text': '<p>ScottGu has a bunch of tricks at <a href="http://weblogs.asp.net/scottgu/archive/2006/04/03/441787.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2006/04/03/441787.aspx</a></p>\n'}, {'answer_id': 55348, 'author': 'Kevin Goff', 'author_id': 1940, 'author_profile': 'https://Stackoverflow.com/users/1940', 'pm_score': 4, 'selected': False, 'text': "<p>If you have ASP.NET generating an RSS feed, it will sometimes put an extra line at the top of the page.  This won't validate with common RSS validators. You can work around it by putting the page directive <code>&lt;@Page&gt;</code> at the bottom of the page.   </p>\n"}, {'answer_id': 55356, 'author': 'Paulj', 'author_id': 5433, 'author_profile': 'https://Stackoverflow.com/users/5433', 'pm_score': 3, 'selected': False, 'text': "<p>I thought it was neat when I dumped a xmlDocument() into a label and it displayed using it's xsl transforms.</p>\n"}, {'answer_id': 58445, 'author': 'Omer van Kloeten', 'author_id': 4979, 'author_profile': 'https://Stackoverflow.com/users/4979', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://ryanfarley.com/blog/archive/2008/08/14/set-browser-specific-asp.net-server-control-properties-and-taking-an.aspx" rel="nofollow noreferrer">Setting Server Control Properties Based on Target Browser</a> and <a href="http://ryanfarley.com/blog/archive/2008/08/14/more-on-device-filtering-with-asp.net-server-control-properties.aspx" rel="nofollow noreferrer">more</a>.</p>\n\n<blockquote>\n<pre><code>&lt;asp:Label runat="server" ID="labelText" \n    ie:Text="This is IE text" \n    mozilla:Text="This is Firefox text" \n    Text="This is general text" \n/&gt;\n</code></pre>\n</blockquote>\n\n<p>That one kinda took me by surprise.</p>\n'}, {'answer_id': 61100, 'author': 'Tyler', 'author_id': 5642, 'author_profile': 'https://Stackoverflow.com/users/5642', 'pm_score': 4, 'selected': False, 'text': '<p>Before ASP.NET v3.5 added routes you could create your own friendly URLs simply by writing an HTTPModule to and rewrite the request early in the page pipeline (like the BeginRequest event).</p>\n\n<p>Urls like <a href="http://servername/page/Param1/SomeParams1/Param2/SomeParams2" rel="nofollow noreferrer">http://servername/page/Param1/SomeParams1/Param2/SomeParams2</a> would get mapped to another page like below (often using regular expressions).</p>\n\n<pre><code>HttpContext.RewritePath("PageHandler.aspx?Param1=SomeParms1&amp;Param2=SomeParams2");\n</code></pre>\n\n<p>DotNetNuke has a really good HttpModule that does this for their friendly urls. Is still useful for machines where you can\'t deploy .NET v3.5.</p>\n'}, {'answer_id': 75162, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 4, 'selected': False, 'text': '<p>Included in ASP.NET 3.5 SP1:</p>\n\n<ul>\n<li>customErrors now supports "redirectMode" attribute with a value of "ResponseRewrite". Shows error page without changing URL.</li>\n<li>The form tag now recognizes the action attribute. Great for when you\'re using URL rewriting</li>\n</ul>\n'}, {'answer_id': 75170, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 8, 'selected': False, 'text': '<p>While testing, you can have emails sent to a folder on your computer instead of an SMTP server. Put this in your web.config:</p>\n\n<pre><code>&lt;system.net&gt;\n    &lt;mailSettings&gt;\n        &lt;smtp deliveryMethod="SpecifiedPickupDirectory"&gt;\n            &lt;specifiedPickupDirectory pickupDirectoryLocation="c:\\Temp\\" /&gt;\n        &lt;/smtp&gt;\n    &lt;/mailSettings&gt;\n&lt;/system.net&gt;\n</code></pre>\n'}, {'answer_id': 123762, 'author': 'cllpse', 'author_id': 20946, 'author_profile': 'https://Stackoverflow.com/users/20946', 'pm_score': 3, 'selected': False, 'text': '<p>Attach a class located in your App_Code folder to your Global Application Class file.</p>\n\n<p><a href="http://aspadvice.com/blogs/kiran/archive/2005/12/11/14301.aspx" rel="nofollow noreferrer">ASP.NET 2.0 - Global.asax - Code Behind file</a>.</p>\n\n<p>This works in Visual Studio 2008 as well.</p>\n'}, {'answer_id': 170091, 'author': 'Atanas Korchev', 'author_id': 10141, 'author_profile': 'https://Stackoverflow.com/users/10141', 'pm_score': 2, 'selected': False, 'text': '<p>You can find any control by using its <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.uniqueid.aspx" rel="nofollow noreferrer">UniqueID</a> property:</p>\n\n<pre><code>Label label = (Label)Page.FindControl("UserControl1$Label1");\n</code></pre>\n'}, {'answer_id': 177078, 'author': 'John Sheehan', 'author_id': 1786, 'author_profile': 'https://Stackoverflow.com/users/1786', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.isdebuggingenabled.aspx" rel="nofollow noreferrer">HttpContext.Current.IsDebuggingEnabled</a></p>\n\n<p>This is great for determining which scripts to output (min or full versions) or anything else you might want in dev, but not live.</p>\n'}, {'answer_id': 191506, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.virtualpathutility_methods.aspx" rel="nofollow noreferrer">System.Web.VirtualPathUtility</a></p>\n'}, {'answer_id': 194142, 'author': 'Chris Pietschmann', 'author_id': 7831, 'author_profile': 'https://Stackoverflow.com/users/7831', 'pm_score': 5, 'selected': False, 'text': '<p>You can use ASP.NET Comments within an .aspx page to comment out full parts of a page including server controls. And the contents that is commented out will never be sent to the client.</p>\n\n<pre><code>&lt;%--\n    &lt;div&gt;\n        &lt;asp:Button runat="server" id="btnOne"/&gt;\n    &lt;/div&gt;\n--%&gt;\n</code></pre>\n'}, {'answer_id': 194153, 'author': 'leppie', 'author_id': 15541, 'author_profile': 'https://Stackoverflow.com/users/15541', 'pm_score': 3, 'selected': False, 'text': '<p>Valid syntax that VS chokes on:</p>\n\n<pre><code>&lt;input type="checkbox" name="roles" value=\'&lt;%# Eval("Name") %&gt;\' \n  &lt;%# ((bool) Eval("InRole")) ? "checked" : "" %&gt; \n  &lt;%# ViewData.Model.IsInRole("Admin") ? "" : "disabled" %&gt; /&gt;\n</code></pre>\n'}, {'answer_id': 384970, 'author': 'Craig McKeachie', 'author_id': 48175, 'author_profile': 'https://Stackoverflow.com/users/48175', 'pm_score': 5, 'selected': False, 'text': '<p>I worked on a asp.net application which went through a security audit by a leading security company and I learned this easy trick to preventing a lesser known but important security vulnerability.</p>\n\n<p>The below explanation is from:\n<a href="http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation#Consider_Using_Page.ViewStateUserKey_to_Counter_One-Click_Attacks" rel="nofollow noreferrer">http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation#Consider_Using_Page.ViewStateUserKey_to_Counter_One-Click_Attacks</a></p>\n\n<p>Consider using Page.ViewStateUserKey to counter one-click attacks. If you authenticate your callers and use ViewState, set the Page.ViewStateUserKey property in the Page_Init event handler to prevent one-click attacks.</p>\n\n<pre><code>void Page_Init (object sender, EventArgs e) {\n  ViewStateUserKey = Session.SessionID;\n}\n</code></pre>\n\n<p>Set the property to a value you know is unique to each user, such as a session ID, user name, or user identifier.</p>\n\n<p>A one-click attack occurs when an attacker creates a Web page (.htm or .aspx) that contains a hidden form field named __VIEWSTATE that is already filled with ViewState data. The ViewState can be generated from a page that the attacker had previously created, such as a shopping cart page with 100 items. The attacker lures an unsuspecting user into browsing to the page, and then the attacker causes the page to be sent to the server where the ViewState is valid. The server has no way of knowing that the ViewState originated from the attacker. ViewState validation and HMACs do not counter this attack because the ViewState is valid and the page is executed under the security context of the user.</p>\n\n<p>By setting the ViewStateUserKey property, when the attacker browses to a page to create the ViewState, the property is initialized to his or her name. When the legitimate user submits the page to the server, it is initialized with the attacker\'s name. As a result, the ViewState HMAC check fails and an exception is generated. </p>\n'}, {'answer_id': 491233, 'author': 'Binoj Antony', 'author_id': 33015, 'author_profile': 'https://Stackoverflow.com/users/33015', 'pm_score': 5, 'selected': False, 'text': '<p>Usage of the ASHX file type: <br />\nIf you want to just output some basic html or xml without going through the page event handlers then you can implement the HttpModule in a simple fashion</p>\n\n<p>Name the page as SomeHandlerPage.ashx and just put the below code (just one line) in it</p>\n\n<pre><code>&lt;%@ webhandler language="C#" class="MyNamespace.MyHandler" %&gt;\n</code></pre>\n\n<p>Then the code file</p>\n\n<pre><code>using System;\nusing System.IO;\nusing System.Web;\n\nnamespace MyNamespace\n{\n    public class MyHandler: IHttpHandler\n    {\n        public void ProcessRequest (HttpContext context)\n        {   \n            context.Response.ContentType = "text/xml";\n            string myString = SomeLibrary.SomeClass.SomeMethod();\n            context.Response.Write(myString);\n        }\n\n        public bool IsReusable\n        {\n            get { return true; }\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 491262, 'author': 'Binoj Antony', 'author_id': 33015, 'author_profile': 'https://Stackoverflow.com/users/33015', 'pm_score': 6, 'selected': False, 'text': '<p>Enabling <strong>intellisense for MasterPages</strong> in the content pages <br />\nI am sure this is a very little known hack</p>\n\n<p>Most of the time you have to use the findcontrol method and cast the controls in master page from the content pages when you want to use them, the <strong>MasterType</strong>  directive will enable intellisense in visual studio once you to this</p>\n\n<p>just add one more directive to the page</p>\n\n<pre><code>&lt;%@ MasterType VirtualPath="~/Masters/MyMainMasterPage.master" %&gt;\n</code></pre>\n\n<p>If you do not want to use the Virtual Path and use the class name instead then </p>\n\n<pre><code>&lt;%@ MasterType TypeName="MyMainMasterPage" %&gt;\n</code></pre>\n\n<p>Get the full article <a href="http://www.simple-talk.com/content/print.aspx?article=398" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 515056, 'author': 'Canavar', 'author_id': 55351, 'author_profile': 'https://Stackoverflow.com/users/55351', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/3hc29e2a.aspx" rel="nofollow noreferrer">ClientScript</a> property on Page object.</p>\n'}, {'answer_id': 572275, 'author': 'andleer', 'author_id': 64262, 'author_profile': 'https://Stackoverflow.com/users/64262', 'pm_score': 5, 'selected': False, 'text': '<p><strong>The Code Expression Builder</strong> </p>\n\n<p>Sample markup:</p>\n\n<pre><code>Text = \'&lt;%$ Code: GetText() %&gt;\'\nText = \'&lt;%$ Code: MyStaticClass.MyStaticProperty %&gt;\'\nText = \'&lt;%$ Code: DateTime.Now.ToShortDateString() %&gt;\'\nMaxLenth = \'&lt;%$ Code: 30 + 40 %&gt;\'\n</code></pre>\n\n<p>The real beauty of the code expression builder is that you can use databinding like expressions in non-databinding situations. You can also create other Expression Builders that perform other functions.</p>\n\n<p>web.config:</p>\n\n<pre><code>&lt;system.web&gt;    \n    &lt;compilation debug="true"&gt;\n        &lt;expressionBuilders&gt;\n            &lt;add expressionPrefix="Code" type="CodeExpressionBuilder" /&gt;\n</code></pre>\n\n<p>The cs class that makes it all happen:</p>\n\n<pre><code>[ExpressionPrefix("Code")]\npublic class CodeExpressionBuilder : ExpressionBuilder\n{\n    public override CodeExpression GetCodeExpression(\n        BoundPropertyEntry entry,\n        object parsedData,\n        ExpressionBuilderContext context)\n    {            \n        return new CodeSnippetExpression(entry.Expression);\n    }\n} \n</code></pre>\n'}, {'answer_id': 574030, 'author': 'John', 'author_id': 19490, 'author_profile': 'https://Stackoverflow.com/users/19490', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.hosting.hostingenvironment.mappath.aspx" rel="nofollow noreferrer">System.Web.Hosting.HostingEnvironment.MapPath</a></p>\n'}, {'answer_id': 818365, 'author': 'Troy Hunt', 'author_id': 73948, 'author_profile': 'https://Stackoverflow.com/users/73948', 'pm_score': 6, 'selected': False, 'text': '<p>Retail mode at the machine.config level: </p>\n\n<pre><code>&lt;configuration&gt;\n  &lt;system.web&gt;\n    &lt;deployment retail="true"/&gt;\n  &lt;/system.web&gt;\n&lt;/configuration&gt;\n</code></pre>\n\n<p>Overrides the web.config settings to enforce debug to false, turns custom errors on and disables tracing. No more forgetting to change attributes before publishing - just leave them all configured for development or test environments and update the production retail setting.</p>\n'}, {'answer_id': 989225, 'author': 'Khaled Musaied', 'author_id': 90657, 'author_profile': 'https://Stackoverflow.com/users/90657', 'pm_score': 3, 'selected': False, 'text': '<p>one feature came to my mind, sometimes you will need to hide some part of your page from the crowlers. you can do it with <strong>javascript</strong> or using this simple code:</p>\n\n<pre><code>if (Request.Browser.Crawler){\n        HideArticleComments();\n</code></pre>\n'}, {'answer_id': 1000605, 'author': 'Canavar', 'author_id': 55351, 'author_profile': 'https://Stackoverflow.com/users/55351', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.ensurechildcontrols.aspx" rel="nofollow noreferrer">EnsureChildControls Method</a> : It checks the child controls if they\'re initiated. If the child controls are not initiated it calls CreateChildControls method.</p>\n'}, {'answer_id': 1069756, 'author': 'Graham', 'author_id': 131785, 'author_profile': 'https://Stackoverflow.com/users/131785', 'pm_score': 4, 'selected': False, 'text': '<p>My team uses this a lot as a hack:</p>\n\n<pre><code>WebRequest myRequest = WebRequest.Create("http://www.google.com");\nWebResponse myResponse = myRequest.GetResponse();\nStreamReader sr = new StreamReader(myResponse.GetResponseStream());\n\n// here\'s page\'s response loaded into a string for further use\n\nString thisReturn = sr.ReadToEnd().Trim();\n</code></pre>\n\n<p>It loads a webpage\'s response as a string. You can send in post parameters too. </p>\n\n<p>We use it in the place of ASCX/AJAX/WebServices when we need something cheap and fast. Basically, its a quick way to access web-available content across servers. In fact, we just dubbed it the "Redneck Web Service" yesterday. </p>\n'}, {'answer_id': 1078420, 'author': 'Scott Hanselman', 'author_id': 6380, 'author_profile': 'https://Stackoverflow.com/users/6380', 'pm_score': 6, 'selected': False, 'text': '<p>Here\'s the best one. Add this to your web.config for MUCH faster compilation. This is post 3.5SP1 via <a href="http://support.microsoft.com/kb/961884" rel="nofollow noreferrer">this QFE</a>.</p>\n\n<pre><code>&lt;compilation optimizeCompilations="true"&gt;\n</code></pre>\n\n<blockquote>\n  <p>Quick summary: we are introducing a\n  new optimizeCompilations switch in\n  ASP.NET that can greatly improve the\n  compilation speed in some scenarios. \n  There are some catches, so read on for\n  more details.  This switch is\n  currently available as a QFE for\n  3.5SP1, and will be part of VS 2010.</p>\n  \n  <p>The ASP.NET compilation system takes a\n  very conservative approach which\n  causes it to wipe out any previous\n  work that it has done any time a ‘top\n  level’ file changes. ‘Top level’ files\n  include anything in bin and App_Code,\n  as well as global.asax. While this\n  works fine for small apps, it becomes\n  nearly unusable for very large apps.\n  E.g. a customer was running into a\n  case where it was taking 10 minutes to\n  refresh a page after making any change\n  to a ‘bin’ assembly.</p>\n  \n  <p>To ease the pain, we added an\n  ‘optimized’ compilation mode which\n  takes a much less conservative\n  approach to recompilation.</p>\n</blockquote>\n\n<p>Via <a href="http://blogs.msdn.com/davidebb/archive/2009/04/15/a-new-flag-to-optimize-asp-net-compilation-behavior.aspx" rel="nofollow noreferrer">here</a>: </p>\n'}, {'answer_id': 1161881, 'author': 'Dan Diplo', 'author_id': 140392, 'author_profile': 'https://Stackoverflow.com/users/140392', 'pm_score': 6, 'selected': False, 'text': '<p><strong>WebMethods.</strong></p>\n\n<p>You can using ASP.NET AJAX callbacks to web methods placed in ASPX pages. You can decorate a static method with the [WebMethod()] and [ScriptMethod()] attributes. For example:</p>\n\n<pre><code>[System.Web.Services.WebMethod()] \n[System.Web.Script.Services.ScriptMethod()] \npublic static List&lt;string&gt; GetFruitBeginingWith(string letter)\n{\n    List&lt;string&gt; products = new List&lt;string&gt;() \n    { \n        "Apple", "Banana", "Blackberry", "Blueberries", "Orange", "Mango", "Melon", "Peach"\n    };\n\n    return products.Where(p =&gt; p.StartsWith(letter)).ToList();\n}\n</code></pre>\n\n<p>Now, in your ASPX page you can do this:</p>\n\n<pre><code>&lt;form id="form1" runat="server"&gt;\n    &lt;div&gt;\n        &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" /&gt;\n        &lt;input type="button" value="Get Fruit" onclick="GetFruit(\'B\')" /&gt;\n    &lt;/div&gt;\n&lt;/form&gt;\n</code></pre>\n\n<p>And call your server side method via JavaScript using:</p>\n\n<pre><code>    &lt;script type="text/javascript"&gt;\n    function GetFruit(l)\n    {\n        PageMethods.GetFruitBeginingWith(l, OnGetFruitComplete);\n    }\n\n    function OnGetFruitComplete(result)\n    {\n        alert("You got fruit: " + result);\n    }\n&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 1205724, 'author': 'CraigTP', 'author_id': 57477, 'author_profile': 'https://Stackoverflow.com/users/57477', 'pm_score': 5, 'selected': False, 'text': '<p>One little known and rarely used feature of ASP.NET is:</p>\n\n<p><a href="http://madskristensen.net/post/Tag-mapping-in-ASPNET.aspx" rel="nofollow noreferrer">Tag Mapping</a></p>\n\n<p>It\'s rarely used because there\'s only a specific situation where you\'d need it, but when you need it, it\'s <em>so</em> handy.</p>\n\n<p>Some articles about this little know feature:</p>\n\n<p><a href="http://madskristensen.net/post/Tag-mapping-in-ASPNET.aspx" rel="nofollow noreferrer">Tag Mapping in ASP.NET</a><br>\n<a href="http://www.fmsinc.com/free/NewTips/NET/tag_mapping.html" rel="nofollow noreferrer">Using Tag Mapping in ASP.NET 2.0</a></p>\n\n<p>and from that last article:</p>\n\n<blockquote>\n  <p>Tag mapping allows you to swap\n  compatible controls at compile time on\n  every page in your web application. A\n  useful example is if you have a stock\n  ASP.NET control, such as a\n  DropDownList, and you want to replace\n  it with a customized control that is\n  derived from DropDownList. This could\n  be a control that has been customized\n  to provide more optimized caching of\n  lookup data. Instead of editing every\n  web form and replacing the built in\n  DropDownLists with your custom\n  version, you can have ASP.NET in\n  effect do it for you by modifying\n  web.config:</p>\n</blockquote>\n\n<pre><code>&lt;pages&gt;\n &lt;tagMapping&gt;\n   &lt;clear /&gt;\n   &lt;add tagType="System.Web.UI.WebControls.DropDownList"\n        mappedTagType="SmartDropDown"/&gt;\n  &lt;/tagMapping&gt;\n&lt;/pages&gt;\n</code></pre>\n'}, {'answer_id': 1355965, 'author': 'MRG', 'author_id': 46281, 'author_profile': 'https://Stackoverflow.com/users/46281', 'pm_score': 3, 'selected': False, 'text': '<p><strong><a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.islocal.aspx" rel="nofollow noreferrer">Request.IsLocal Property :</a></strong></p>\n\n<p>It indicates whether current request is coming from Local Computer or not. </p>\n\n<pre><code>if( Request.IsLocal )\n{\n   LoadLocalAdminMailSettings();\n}\nelse\n{\n   LoadServerAdminMailSettings();\n}\n</code></pre>\n'}, {'answer_id': 1357104, 'author': 'MRG', 'author_id': 46281, 'author_profile': 'https://Stackoverflow.com/users/46281', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx" rel="nofollow noreferrer">DefaultButton</a> property in Panels.</p>\n\n<p>It sets default button for a particular panel.</p>\n'}, {'answer_id': 1357122, 'author': 'MRG', 'author_id': 46281, 'author_profile': 'https://Stackoverflow.com/users/46281', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.maintainscrollpositiononpostback.aspx" rel="nofollow noreferrer">MaintainScrollPositionOnPostback</a> attribute in Page directive. It is used to maintain scroll position of aspx page across postbacks.</p>\n'}, {'answer_id': 1738028, 'author': 'RickNZ', 'author_id': 211378, 'author_profile': 'https://Stackoverflow.com/users/211378', 'pm_score': 6, 'selected': False, 'text': '<p>Check to see if the client is still connected, before starting a long-running task:</p>\n\n<pre><code>if (this.Response.IsClientConnected)\n{\n  // long-running task\n}\n</code></pre>\n'}, {'answer_id': 1810914, 'author': 'Wagner Danda da Silva Filho', 'author_id': 222328, 'author_profile': 'https://Stackoverflow.com/users/222328', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Similarly to the optimizeCompilations=”true” solution, here another one to speed up the time you spend waiting in between builds</strong> (very good especially if you are working with a large project):  <strong>create a ram-based drive (i.e. using RamDisk) and change your default “Temporary ASP.NET Files” to this memory-based drive.</strong></p>\n\n<p>The full details on how to do this is on my blog: <a href="http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/" rel="nofollow noreferrer">http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/</a></p>\n\n<p>Basically you first and configure a RamDisk (again, in my blog there a link to a free ramdisk) and then you change your web.config according to this:</p>\n\n<pre><code> &lt;system.web&gt;\n ....\n     &lt;compilation debug="true" tempDirectory="R:\\ASP_NET_TempFiles\\"&gt;\n     ....\n     &lt;/compilation&gt;\n ....\n &lt;/system.web&gt;\n</code></pre>\n\n<p>It greatly increase my development time, you just need invest in memory for you computer :)</p>\n\n<p>Happy Programming!</p>\n\n<p>Wagner Danda</p>\n'}, {'answer_id': 2138151, 'author': 'womp', 'author_id': 63756, 'author_profile': 'https://Stackoverflow.com/users/63756', 'pm_score': 4, 'selected': False, 'text': '<p>Did you know it\'s possible to run ASP.Net outside of IIS or Visual Studio?</p>\n\n<p>The whole runtime is packaged up and ready to be hosted in any process that wants to give it a try.  Using <code>ApplicationHost</code>, <code>HttpRuntime</code> and <code>HttpApplication</code> classes, you too can grind up those .aspx pages and get shiny HTML output from them.</p>\n\n<pre><code>HostingClass host = ApplicationHost.CreateApplicationHost(typeof(HostingClass), \n                                            "/virtualpath", "physicalPath");\nhost.ProcessPage(urlToAspxFile); \n</code></pre>\n\n<p>And your hosting class:</p>\n\n<pre><code>public class HostingClass : MarshalByRefObject\n{\n    public void ProcessPage(string url)\n    {\n        using (StreamWriter sw = new StreamWriter("C:\\temp.html"))\n        {\n            SimpleWorkerRequest worker = new SimpleWorkerRequest(url, null, sw);\n            HttpRuntime.ProcessRequest(worker);\n        }\n                    // Ta-dah!  C:\\temp.html has some html for you.\n    }\n}\n</code></pre>\n'}, {'answer_id': 2510617, 'author': 'Ivo S', 'author_id': 301130, 'author_profile': 'https://Stackoverflow.com/users/301130', 'pm_score': 2, 'selected': False, 'text': '<p>If you use web services instead WCF services, you can still use standard .Net membership to enforce authentication and login session behaviour\non a set web services similarly to a how you would secure web site with membership forms authentication &amp; without the need for a special session\nand/or soap headers implementations by simply calling System.Web.Security.FormsAuthentication.SetAuthCookie(userName, false) [after calling\nMembership.ValidateUser(userName, password) of course] to create cookie in the response as if the user has logged in via a web form.\nThen you can retrieve this authentication cookie with Response.Cookies[].Value and return it as a string to the user\nwhich can be used to authenticate the user in subsequent calls by re-creating the cookie in the  Application_BeginRequest by extracting the<br>\ncookie method call param from the Request.InputStream and re-creating the auth cookie before the membership authenticates the request this way the\nmembership provider gets tricked and will know the request is authenticated and enforce all its rules. </p>\n\n<p>Sample web method signature to return this cookie to the user would be:\nstring Login(userName,password) </p>\n\n<p>Sample subsequent web method call would be:\nstring DoSomething(string authcookie,string methodParam1,int methodParam2 etc,etc) where you need to extract authcookie(which is value obtained from Login method) param from the Request.InputStreamis </p>\n\n<p>This also simulates a login session and calling FormsAuthentication.SignOut in a web method like this Logout(authcookie) would\nmake the user need to sign in again.</p>\n'}, {'answer_id': 3002736, 'author': 'Diego C.', 'author_id': 80268, 'author_profile': 'https://Stackoverflow.com/users/80268', 'pm_score': 2, 'selected': False, 'text': '<p>Lots of people mentioned how to optimize your code when recompiling. Recently I discovered I can do most of my development (code-behind stuff) in the aspx page and skipping completely the build step. Just save the file and refresh your page.  All you have to do is wrap your code in the following tag:</p>\n\n<pre><code>&lt;script runat="server"&gt;\n\n   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n     Response.Write("Look Ma\', I didn\'t even had to build!")\n   End Sub\n\n&lt;/script&gt;\n</code></pre>\n\n<p>Once you are done, Just move all to the code-behind, build, test everything works and voila!</p>\n\n<p>-D</p>\n'}, {'answer_id': 3011857, 'author': 'Dave', 'author_id': 69039, 'author_profile': 'https://Stackoverflow.com/users/69039', 'pm_score': -1, 'selected': False, 'text': '<p>One of the things I use that work with multiple versions of VB, VBScript and VB.NET is to convert the recordset values to string to eliminate muliple tests for NULL or blank. i.e. <code>Trim(rsData("FieldName").Value &amp; " ")</code>\n<BR>In the case of a whole number value this would be: <code>CLng("0" &amp; Trim(rsData("FieldName").Value &amp; " "))</code></p>\n'}, {'answer_id': 3163868, 'author': 'Ramesh', 'author_id': 168464, 'author_profile': 'https://Stackoverflow.com/users/168464', 'pm_score': -1, 'selected': False, 'text': '<p>After the website was published and deployed in the production server, If we need to do some changes on the server side button click event. We can override the existing click event by using the <code>new</code>keyword in the aspx page itself.</p>\n\n<p>Example</p>\n\n<p><strong>Code Behind Method</strong></p>\n\n<pre><code> Protected void button_click(sender object, e System.EventArgs) \n  {\n     Response.Write("Look Ma\', I Am code behind code!")  \n  }\n</code></pre>\n\n<p><strong>OverRided Method:</strong></p>\n\n<pre><code>&lt;script runat="server"&gt;   \n   Protected void new button_click(sender object, e System.EventArgs) \n  {\n     Response.Write("Look Ma\', I am overrided method!")  \n  }\n\n&lt;/script\n</code></pre>\n\n<p>In this way we can easily fix the production server errors without redeployment.</p>\n'}, {'answer_id': 4412956, 'author': 'Ryan Shripat', 'author_id': 1943, 'author_profile': 'https://Stackoverflow.com/users/1943', 'pm_score': 4, 'selected': False, 'text': '<p><strong>Using configSource to split configuration files.</strong></p>\n\n<p>You can use the configSource attribute in a web.config file to push configuration elements to other .config files, for example,\ninstead of:</p>\n\n<pre><code>    &lt;appSettings&gt;\n        &lt;add key="webServiceURL" value="https://some/ws.url" /&gt;\n        &lt;!-- some more keys --&gt;\n    &lt;/appSettings&gt;\n</code></pre>\n\n<p>...you can have the entire appSettings section stored in another configuration file. Here\'s the new <code>web.config</code> : </p>\n\n<pre><code>    &lt;appSettings configSource="myAppSettings.config" /&gt;\n</code></pre>\n\n<p>The <code>myAppSettings.config</code> file :</p>\n\n<pre><code>    &lt;appSettings&gt;        \n        &lt;add key="webServiceURL" value="https://some/ws.url" /&gt;\n        &lt;!-- some more keys --&gt;\n    &lt;/appSettings&gt;\n</code></pre>\n\n<p>This is quite useful for scenarios where you deploy an application to a customer and you don\'t want them interfering with the web.config file itself and just want them to be able to change just a few settings.</p>\n\n<p>ref: <a href="http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx" rel="nofollow">http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx</a></p>\n'}, {'answer_id': 4438941, 'author': 'TRIVER', 'author_id': 541678, 'author_profile': 'https://Stackoverflow.com/users/541678', 'pm_score': 1, 'selected': False, 'text': '<p>Application variables can be used with web application for communicating across the whole application. It is initialized in Global.asax file and used over the pages in that web application by all the user independent of the session they create.</p>\n'}, {'answer_id': 4536543, 'author': 'chandmk', 'author_id': 6130, 'author_profile': 'https://Stackoverflow.com/users/6130', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/ms228154.aspx" rel="nofollow">\'file\'</a> attribute on appsettings element in web.config.</p>\n\n<p><em>Specifies a relative path to an external file that contains custom application configuration settings.</em></p>\n\n<p>If you have few app settings out of many that need to modified on different environments (prod), this is excellent choice. </p>\n\n<p><em>Because any changes to the Web.config file cause the application to restart, using a separate file allows users to modify values that are in the appSettings section without causing the application to restart. The contents of the separate file are merged with the appSettings section in the Web.config file.</em> </p>\n'}, {'answer_id': 4797525, 'author': 'frankadelic', 'author_id': 52529, 'author_profile': 'https://Stackoverflow.com/users/52529', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.webpronews.com/expertarticles/2006/11/06/using-the-compilationmode-attribute-to-boost-performance" rel="nofollow">CompilationMode="Never"</a> is a feature which can be crucial in certain ASP.NET sites.</p>\n\n<p>If you have an ASP.NET application where ASPX pages are frequently generated and updated via a CMS or other publishing system, it is important to use CompilationMode="Never".</p>\n\n<p>Without this setting, the ASPX file changes will trigger recompilations which will quickly make your appdomain restart. This can wipe out session state and httpruntime cache, not to mention lag caused by recompilation.</p>\n\n<p>(To prevent recompilation you <em>could</em> increase the <a href="http://msdn.microsoft.com/en-us/library/s10awwz0.aspx" rel="nofollow">numRecompilesBeforeAppRestart</a> setting, but that is not ideal as it consumes more memory.)</p>\n\n<p>One caveat to this feature is that the ASPX pages cannot contain any code blocks. To get around this, one may place code in custom controls and/or base classes.</p>\n\n<p>This feature is mostly irrelevant in cases where ASPX pages don\'t change often.</p>\n'}, {'answer_id': 6434945, 'author': 'Bart Verkoeijen', 'author_id': 70182, 'author_profile': 'https://Stackoverflow.com/users/70182', 'pm_score': 0, 'selected': False, 'text': '<p>It\'s possible to package ASPX pages into a Library (.dll), and serve them with the ASP.NET engine.</p>\n\n<p>You will need to implement your own <a href="http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx" rel="nofollow">VirtualPathProvider</a>, which will load via Relfection specific DLL\'s, or you could include the DLL name in your pathname. It\'s up to you.</p>\n\n<p>The magic happens when overriding the <a href="http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualfile.open.aspx" rel="nofollow">VirtualFile.Open</a> method, where you return the ASPX file as a resource from the Assembly class: <a href="http://msdn.microsoft.com/en-us/library/xc4235zt.aspx" rel="nofollow">Assembly.GetManifestResourceStream</a>. The ASP.NET engine will process the resource since it is served via the VirtualPathProvider.</p>\n\n<p>This allows to plug-in pages, or like I did, use it to include a HttpHandler with a control.</p>\n'}, {'answer_id': 7574607, 'author': 'roland', 'author_id': 313353, 'author_profile': 'https://Stackoverflow.com/users/313353', 'pm_score': 3, 'selected': False, 'text': '<p>By default any web form page inherits from <code>System.Web.UI.Page</code> class. What if you want your pages to inherit from a custom base class, which inherits from <code>System.Web.UI.Page</code>? </p>\n\n<p>There is a way to constraint any page to inherit from your own base class. Simply add a new line on your <code>web.config</code>:</p>\n\n<pre><code>&lt;system.web&gt;\n    &lt;pages pageBaseType="MyBasePageClass" /&gt;\n&lt;/system.web&gt;\n</code></pre>\n\n<p>Caution: this is only valid if your class is a stand-alone one. I mean a class that has no code-behind, which looks like <code>&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt;</code></p>\n'}, {'answer_id': 8461437, 'author': 'Michiel van Oosterhout', 'author_id': 4830, 'author_profile': 'https://Stackoverflow.com/users/4830', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/36574bf6%28v=VS.100%29.aspx" rel="nofollow">Templated user controls</a>. Once you know how they work you will see all sorts of possibilities. Here\'s the simplest implementation:</p>\n\n<p><strong>TemplatedControl.ascx</strong></p>\n\n<p>The great thing here is using the easy and familiar user control building block and being able to layout the different parts of your UI using HTML and some placeholders.</p>\n\n<pre><code>&lt;%@ Control Language="C#" CodeFile="TemplatedControl.ascx.cs" Inherits="TemplatedControl" %&gt;\n\n&lt;div class="header"&gt;\n    &lt;asp:PlaceHolder ID="HeaderPlaceHolder" runat="server" /&gt;\n&lt;/div&gt;\n&lt;div class="body"&gt;\n    &lt;asp:PlaceHolder ID="BodyPlaceHolder" runat="server" /&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p><strong>TemplatedControl.ascx.cs</strong></p>\n\n<p>The \'secret\' here is using public properties of type <code>ITemplate</code> and knowing about the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx" rel="nofollow"><code>[ParseChildren]</code></a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.persistencemodeattribute.aspx" rel="nofollow"><code>[PersistenceMode]</code></a> attributes.</p>\n\n<pre><code>using System.Web.UI;\n\n[ParseChildren(true)]\npublic partial class TemplatedControl : System.Web.UI.UserControl\n{\n    [PersistenceMode(PersistenceMode.InnerProperty)]\n    public ITemplate Header { get; set; }\n\n    [PersistenceMode(PersistenceMode.InnerProperty)]\n    public ITemplate Body { get; set; }\n\n    void Page_Init()\n    {\n        if (Header != null)\n            Header.InstantiateIn(HeaderPlaceHolder);\n\n        if (Body != null)\n            Body.InstantiateIn(BodyPlaceHolder);\n    }\n}\n</code></pre>\n\n<p><strong>Default.aspx</strong></p>\n\n<pre><code>&lt;%@ Register TagPrefix="uc" TagName="TemplatedControl" Src="TemplatedControl.ascx" %&gt;\n\n&lt;uc:TemplatedControl runat="server"&gt;\n    &lt;Header&gt;Lorem ipsum&lt;/Header&gt;\n    &lt;Body&gt;\n        // You can add literal text, HTML and server controls to the templates\n        &lt;p&gt;Hello &lt;asp:Label runat="server" Text="world" /&gt;!&lt;/p&gt;\n    &lt;/Body&gt;\n&lt;/uc:TemplatedControl&gt;\n</code></pre>\n\n<p>You will even get IntelliSense for the inner template properties. So if you work in a team you can quickly create reusable UI to achieve the same composability that your team already enjoys from the built-in ASP.NET server controls.</p>\n\n<p>The <a href="http://msdn.microsoft.com/en-us/library/36574bf6.aspx" rel="nofollow">MSDN example</a> (same link as the beginning) adds some extra controls and a naming container, but that only becomes necessary if you want to support \'repeater-type\' controls. </p>\n'}]
['https://Stackoverflow.com/questions/54929', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/380/']