Hidden Features of ASP.NET

asp.net.Net

asp.net Problem Overview


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


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.

What are the ones that you know?

asp.net Solutions


Solution 1 - asp.net

While testing, you can have emails sent to a folder on your computer instead of an SMTP server. Put this in your web.config:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
        </smtp>
    </mailSettings>
</system.net>

Solution 2 - asp.net

If you place a file named app_offline.htm in 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 for all new requests.

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.

Also, as pointed out by marxidad, make sure you have at least 512 bytes of content within the file so IE6 will render it correctly.

Solution 3 - asp.net

throw new HttpException(404, "Article not found");

This will be caught by ASP.NET which will return the customErrors page. Learned about this one in a recent .NET Tip of the Day Post

Solution 4 - asp.net

Here's the best one. Add this to your web.config for MUCH faster compilation. This is post 3.5SP1 via this QFE.

<compilation optimizeCompilations="true">

> Quick summary: we are introducing a > new optimizeCompilations switch in > ASP.NET that can greatly improve the > compilation speed in some scenarios. > There are some catches, so read on for > more details. This switch is > currently available as a QFE for > 3.5SP1, and will be part of VS 2010. > > The ASP.NET compilation system takes a > very conservative approach which > causes it to wipe out any previous > work that it has done any time a ‘top > level’ file changes. ‘Top level’ files > include anything in bin and App_Code, > as well as global.asax. While this > works fine for small apps, it becomes > nearly unusable for very large apps. > E.g. a customer was running into a > case where it was taking 10 minutes to > refresh a page after making any change > to a ‘bin’ assembly. > > To ease the pain, we added an > ‘optimized’ compilation mode which > takes a much less conservative > approach to recompilation.

Via here:

Solution 5 - asp.net

  • HttpContext.Current 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).

  • You can continue executing code on the same page after redirecting the user to another one by calling Response.Redirect(url, false )

  • You don't need .ASPX files if all you want is a compiled Page (or any IHttpHandler). Just set the path and HTTP methods to point to the class in the <httpHandlers> element in the web.config file.

  • A Page object can be retrieved from an .ASPX file programmatically by calling PageParser.GetCompiledPageInstance(virtualPath,aspxFileName,Context)

Solution 6 - asp.net

Retail mode at the machine.config level:

<configuration>
  <system.web>
    <deployment retail="true"/>
  </system.web>
</configuration>

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.

Solution 7 - asp.net

Enabling intellisense for MasterPages in the content pages
I am sure this is a very little known hack

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 MasterType directive will enable intellisense in visual studio once you to this

just add one more directive to the page

<%@ MasterType VirtualPath="~/Masters/MyMainMasterPage.master" %>

If you do not want to use the Virtual Path and use the class name instead then

<%@ MasterType TypeName="MyMainMasterPage" %>

Get the full article [here][1] [1]: http://www.simple-talk.com/content/print.aspx?article=398

Solution 8 - asp.net

HttpContext.Items as a request-level caching tool

Solution 9 - asp.net

Two things stand out in my head:

  1. You can turn Trace on and off from the code:

    #ifdef DEBUG if (Context.Request.QueryString["DoTrace"] == "true") { Trace.IsEnabled = true; Trace.Write("Application:TraceStarted"); } #endif

  2. You can build multiple .aspx pages using only one shared "code-behind" file.

Build one class .cs file :

public class Class1:System.Web.UI.Page
    {
        public TextBox tbLogin;

        protected void Page_Load(object sender, EventArgs e)
        {

          if (tbLogin!=null)
            tbLogin.Text = "Hello World";
        }
    }

and then you can have any number of .aspx pages (after you delete .designer.cs and .cs code-behind that VS has generated) :

  <%@ Page Language="C#"  AutoEventWireup="true"  Inherits="Namespace.Class1" %>
     <form id="form1" runat="server">
     <div>
     <asp:TextBox  ID="tbLogin" runat="server"></asp: TextBox  >
     </div>
     </form>

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.

Solution 10 - asp.net

You can use:

 Request.Params[Control.UniqueId] 

To get the value of a control BEFORE viewstate is initialized (Control.Text etc will be empty at this point).

This is useful for code in Init.

Solution 11 - asp.net

WebMethods.

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:

[System.Web.Services.WebMethod()] 
[System.Web.Script.Services.ScriptMethod()] 
public static List<string> GetFruitBeginingWith(string letter)
{
	List<string> products = new List<string>() 
	{ 
		"Apple", "Banana", "Blackberry", "Blueberries", "Orange", "Mango", "Melon", "Peach"
	};

	return products.Where(p => p.StartsWith(letter)).ToList();
}

Now, in your ASPX page you can do this:

<form id="form1" runat="server">
	<div>
		<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
		<input type="button" value="Get Fruit" onclick="GetFruit('B')" />
	</div>
</form>

And call your server side method via JavaScript using:

	<script type="text/javascript">
	function GetFruit(l)
	{
		PageMethods.GetFruitBeginingWith(l, OnGetFruitComplete);
	}

	function OnGetFruitComplete(result)
	{
		alert("You got fruit: " + result);
	}
</script>

Solution 12 - asp.net

Check to see if the client is still connected, before starting a long-running task:

if (this.Response.IsClientConnected)
{
  // long-running task
}

Solution 13 - asp.net

One little known and rarely used feature of ASP.NET is:

Tag Mapping

It's rarely used because there's only a specific situation where you'd need it, but when you need it, it's so handy.

Some articles about this little know feature:

Tag Mapping in ASP.NET
Using Tag Mapping in ASP.NET 2.0

and from that last article:

> Tag mapping allows you to swap > compatible controls at compile time on > every page in your web application. A > useful example is if you have a stock > ASP.NET control, such as a > DropDownList, and you want to replace > it with a customized control that is > derived from DropDownList. This could > be a control that has been customized > to provide more optimized caching of > lookup data. Instead of editing every > web form and replacing the built in > DropDownLists with your custom > version, you can have ASP.NET in > effect do it for you by modifying > web.config:

<pages>
 <tagMapping>
   <clear />
   <add tagType="System.Web.UI.WebControls.DropDownList"
        mappedTagType="SmartDropDown"/>
  </tagMapping>
</pages>

Solution 14 - asp.net

HttpModules. The architecture is crazy elegant. Maybe not a hidden feature, but cool none the less.

Solution 15 - asp.net

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.

<%--
    <div>
        <asp:Button runat="server" id="btnOne"/>
    </div>
--%>

Solution 16 - asp.net

The Code Expression Builder

Sample markup:

Text = '<%$ Code: GetText() %>'
Text = '<%$ Code: MyStaticClass.MyStaticProperty %>'
Text = '<%$ Code: DateTime.Now.ToShortDateString() %>'
MaxLenth = '<%$ Code: 30 + 40 %>'

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.

web.config:

<system.web>    
    <compilation debug="true">
        <expressionBuilders>
            <add expressionPrefix="Code" type="CodeExpressionBuilder" />

The cs class that makes it all happen:

[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
    public override CodeExpression GetCodeExpression(
        BoundPropertyEntry entry,
        object parsedData,
        ExpressionBuilderContext context)
    {            
        return new CodeSnippetExpression(entry.Expression);
    }
} 

Solution 17 - asp.net

Usage of the ASHX file type:
If 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

Name the page as SomeHandlerPage.ashx and just put the below code (just one line) in it

<%@ webhandler language="C#" class="MyNamespace.MyHandler" %>

Then the code file

using System;
using System.IO;
using System.Web;

namespace MyNamespace
{
	public class MyHandler: IHttpHandler
	{
		public void ProcessRequest (HttpContext context)
		{   
			context.Response.ContentType = "text/xml";
			string myString = SomeLibrary.SomeClass.SomeMethod();
			context.Response.Write(myString);
		}

		public bool IsReusable
		{
			get { return true; }
		}
	}
}

Solution 18 - asp.net

Setting Server Control Properties Based on Target Browser and more.

> ie:Text="This is IE text" > mozilla:Text="This is Firefox text" > Text="This is general text" > />

That one kinda took me by surprise.

Solution 19 - asp.net

Solution 20 - asp.net

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.

The below explanation is from: http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation#Consider_Using_Page.ViewStateUserKey_to_Counter_One-Click_Attacks

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.

void Page_Init (object sender, EventArgs e) {
  ViewStateUserKey = Session.SessionID;
}

Set the property to a value you know is unique to each user, such as a session ID, user name, or user identifier.

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.

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.

Solution 21 - asp.net

HttpContext.Current.IsDebuggingEnabled

This is great for determining which scripts to output (min or full versions) or anything else you might want in dev, but not live.

Solution 22 - asp.net

Included in ASP.NET 3.5 SP1:

  • customErrors now supports "redirectMode" attribute with a value of "ResponseRewrite". Shows error page without changing URL.
  • The form tag now recognizes the action attribute. Great for when you're using URL rewriting

Solution 23 - asp.net

DefaultButton property in Panels.

It sets default button for a particular panel.

Solution 24 - asp.net

Solution 25 - asp.net

Using configSource to split configuration files.

You can use the configSource attribute in a web.config file to push configuration elements to other .config files, for example, instead of:

    <appSettings>
        <add key="webServiceURL" value="https://some/ws.url" />
        <!-- some more keys -->
    </appSettings>

...you can have the entire appSettings section stored in another configuration file. Here's the new web.config :

    <appSettings configSource="myAppSettings.config" />

The myAppSettings.config file :

    <appSettings>        
        <add key="webServiceURL" value="https://some/ws.url" />
        <!-- some more keys -->
    </appSettings>

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.

ref: http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx

Solution 26 - asp.net

MaintainScrollPositionOnPostback attribute in Page directive. It is used to maintain scroll position of aspx page across postbacks.

Solution 27 - asp.net

HttpContext.IsCustomErrorEnabled is a cool feature.I've found it useful more than once. Here is a short post about it.

Solution 28 - asp.net

By default, any content between tags for a custom control is added as a child control. This can be intercepted in an AddParsedSubObject() override for filtering or additional parsing (e.g., of text content in LiteralControls):

    protected override void AddParsedSubObject(object obj)
     { var literal = obj as LiteralControl;
       if (literal != null) Controls.Add(parseControl(literal.Text));
       else base.AddParsedSubObject(obj);
     }

...

   <uc:MyControl runat='server'>
     ...this text is parsed as a LiteralControl...
  </uc:MyControl>

Solution 29 - asp.net

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 <@Page> at the bottom of the page.

Solution 30 - asp.net

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).

Urls like http://servername/page/Param1/SomeParams1/Param2/SomeParams2 would get mapped to another page like below (often using regular expressions).

HttpContext.RewritePath("PageHandler.aspx?Param1=SomeParms1&Param2=SomeParams2");

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.

Solution 31 - asp.net

My team uses this a lot as a hack:

WebRequest myRequest = WebRequest.Create("http://www.google.com");
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());

// here's page's response loaded into a string for further use

String thisReturn = sr.ReadToEnd().Trim();

It loads a webpage's response as a string. You can send in post parameters too.

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.

Solution 32 - asp.net

Did you know it's possible to run ASP.Net outside of IIS or Visual Studio?

The whole runtime is packaged up and ready to be hosted in any process that wants to give it a try. Using ApplicationHost, HttpRuntime and HttpApplication classes, you too can grind up those .aspx pages and get shiny HTML output from them.

HostingClass host = ApplicationHost.CreateApplicationHost(typeof(HostingClass), 
                                            "/virtualpath", "physicalPath");
host.ProcessPage(urlToAspxFile); 

And your hosting class:

public class HostingClass : MarshalByRefObject
{
	public void ProcessPage(string url)
	{
		using (StreamWriter sw = new StreamWriter("C:\temp.html"))
		{
		    SimpleWorkerRequest worker = new SimpleWorkerRequest(url, null, sw);
		    HttpRuntime.ProcessRequest(worker);
		}
                    // Ta-dah!  C:\temp.html has some html for you.
	}
}

Solution 33 - asp.net

CompilationMode="Never" is a feature which can be crucial in certain ASP.NET sites.

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".

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.

(To prevent recompilation you could increase the numRecompilesBeforeAppRestart setting, but that is not ideal as it consumes more memory.)

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.

This feature is mostly irrelevant in cases where ASPX pages don't change often.

Solution 34 - asp.net

Valid syntax that VS chokes on:

<input type="checkbox" name="roles" value='<%# Eval("Name") %>' 
  <%# ((bool) Eval("InRole")) ? "checked" : "" %> 
  <%# ViewData.Model.IsInRole("Admin") ? "" : "disabled" %> />

Solution 35 - asp.net

Solution 36 - asp.net

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 javascript or using this simple code:

if (Request.Browser.Crawler){
        HideArticleComments();
	

Solution 37 - asp.net

Similarly to the optimizeCompilations=”true” solution, here another one to speed up the time you spend waiting in between builds (very good especially if you are working with a large project): create a ram-based drive (i.e. using RamDisk) and change your default “Temporary ASP.NET Files” to this memory-based drive.

The full details on how to do this is on my blog: http://www.wagnerdanda.me/2009/11/speeding-up-build-times-in-asp-net-with-ramdisk/

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:

 <system.web>
 ....
     <compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
     ....
     </compilation>
 ....
 </system.web>

It greatly increase my development time, you just need invest in memory for you computer :)

Happy Programming!

Wagner Danda

Solution 38 - asp.net

I thought it was neat when I dumped a xmlDocument() into a label and it displayed using it's xsl transforms.

Solution 39 - asp.net

Request.IsLocal Property :

It indicates whether current request is coming from Local Computer or not.

if( Request.IsLocal )
{
   LoadLocalAdminMailSettings();
}
else
{
   LoadServerAdminMailSettings();
}

Solution 40 - asp.net

By default any web form page inherits from System.Web.UI.Page class. What if you want your pages to inherit from a custom base class, which inherits from System.Web.UI.Page?

There is a way to constraint any page to inherit from your own base class. Simply add a new line on your web.config:

<system.web>
    <pages pageBaseType="MyBasePageClass" />
</system.web>

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 <%@ Page Language="C#" AutoEventWireup="true" %>

Solution 41 - asp.net

Attach a class located in your App_Code folder to your Global Application Class file.

http://aspadvice.com/blogs/kiran/archive/2005/12/11/14301.aspx">ASP.NET 2.0 - Global.asax - Code Behind file.

This works in Visual Studio 2008 as well.

Solution 42 - asp.net

EnsureChildControls Method : It checks the child controls if they're initiated. If the child controls are not initiated it calls CreateChildControls method.

Solution 43 - asp.net

You can find any control by using its UniqueID property:

Label label = (Label)Page.FindControl("UserControl1$Label1");

Solution 44 - asp.net

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:

<script runat="server">

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     Response.Write("Look Ma', I didn't even had to build!")
   End Sub

</script>

Once you are done, Just move all to the code-behind, build, test everything works and voila!

-D

Solution 45 - asp.net

ClientScript property on Page object.

Solution 46 - asp.net

If you use web services instead WCF services, you can still use standard .Net membership to enforce authentication and login session behaviour on a set web services similarly to a how you would secure web site with membership forms authentication & without the need for a special session and/or soap headers implementations by simply calling System.Web.Security.FormsAuthentication.SetAuthCookie(userName, false) [after calling Membership.ValidateUser(userName, password) of course] to create cookie in the response as if the user has logged in via a web form. Then you can retrieve this authentication cookie with Response.Cookies[].Value and return it as a string to the user which can be used to authenticate the user in subsequent calls by re-creating the cookie in the Application_BeginRequest by extracting the
cookie method call param from the Request.InputStream and re-creating the auth cookie before the membership authenticates the request this way the membership provider gets tricked and will know the request is authenticated and enforce all its rules.

Sample web method signature to return this cookie to the user would be: string Login(userName,password)

Sample subsequent web method call would be: string 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

This also simulates a login session and calling FormsAuthentication.SignOut in a web method like this Logout(authcookie) would make the user need to sign in again.

Solution 47 - asp.net

'file' attribute on appsettings element in web.config.

Specifies a relative path to an external file that contains custom application configuration settings.

If you have few app settings out of many that need to modified on different environments (prod), this is excellent choice.

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.

Solution 48 - asp.net

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.

Solution 49 - asp.net

It's possible to package ASPX pages into a Library (.dll), and serve them with the ASP.NET engine.

You will need to implement your own VirtualPathProvider, which will load via Relfection specific DLL's, or you could include the DLL name in your pathname. It's up to you.

The magic happens when overriding the VirtualFile.Open method, where you return the ASPX file as a resource from the Assembly class: Assembly.GetManifestResourceStream. The ASP.NET engine will process the resource since it is served via the VirtualPathProvider.

This allows to plug-in pages, or like I did, use it to include a HttpHandler with a control.

Solution 50 - asp.net

Templated user controls. Once you know how they work you will see all sorts of possibilities. Here's the simplest implementation:

TemplatedControl.ascx

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.

<%@ Control Language="C#" CodeFile="TemplatedControl.ascx.cs" Inherits="TemplatedControl" %>

<div class="header">
    <asp:PlaceHolder ID="HeaderPlaceHolder" runat="server" />
</div>
<div class="body">
    <asp:PlaceHolder ID="BodyPlaceHolder" runat="server" />
</div>

TemplatedControl.ascx.cs

The 'secret' here is using public properties of type ITemplate and knowing about the [ParseChildren] and [PersistenceMode] attributes.

using System.Web.UI;

[ParseChildren(true)]
public partial class TemplatedControl : System.Web.UI.UserControl
{
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate Header { get; set; }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate Body { get; set; }

    void Page_Init()
    {
        if (Header != null)
            Header.InstantiateIn(HeaderPlaceHolder);

        if (Body != null)
            Body.InstantiateIn(BodyPlaceHolder);
    }
}

Default.aspx

<%@ Register TagPrefix="uc" TagName="TemplatedControl" Src="TemplatedControl.ascx" %>

<uc:TemplatedControl runat="server">
    <Header>Lorem ipsum</Header>
    <Body>
        // You can add literal text, HTML and server controls to the templates
        <p>Hello <asp:Label runat="server" Text="world" />!</p>
    </Body>
</uc:TemplatedControl>

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.

The MSDN example (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.

Solution 51 - asp.net

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. Trim(rsData("FieldName").Value & " ")
In the case of a whole number value this would be: CLng("0" & Trim(rsData("FieldName").Value & " "))

Solution 52 - asp.net

This seems like a huge, vague question... But I will throw in Reflection, as it has allowed me to do some incredibly powerful things like pluggable DALs and such.

Solution 53 - asp.net

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 newkeyword in the aspx page itself.

Example

Code Behind Method

 Protected void button_click(sender object, e System.EventArgs) 
  {
     Response.Write("Look Ma', I Am code behind code!")  
  }

OverRided Method:

<script runat="server">   
   Protected void new button_click(sender object, e System.EventArgs) 
  {
     Response.Write("Look Ma', I am overrided method!")  
  }
      
</script

In this way we can easily fix the production server errors without redeployment.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVaibhavView Question on Stackoverflow
Solution 1 - asp.netJohn SheehanView Answer on Stackoverflow
Solution 2 - asp.netTroy DeMonbreunView Answer on Stackoverflow
Solution 3 - asp.netJohn SheehanView Answer on Stackoverflow
Solution 4 - asp.netScott HanselmanView Answer on Stackoverflow
Solution 5 - asp.netMark CidadeView Answer on Stackoverflow
Solution 6 - asp.netTroy HuntView Answer on Stackoverflow
Solution 7 - asp.netBinoj AntonyView Answer on Stackoverflow
Solution 8 - asp.netJohn SheehanView Answer on Stackoverflow
Solution 9 - asp.netRadu094View Answer on Stackoverflow
Solution 10 - asp.netFlySwatView Answer on Stackoverflow
Solution 11 - asp.netDan DiploView Answer on Stackoverflow
Solution 12 - asp.netRickNZView Answer on Stackoverflow
Solution 13 - asp.netCraigTPView Answer on Stackoverflow
Solution 14 - asp.netAllain LalondeView Answer on Stackoverflow
Solution 15 - asp.netChris PietschmannView Answer on Stackoverflow
Solution 16 - asp.netandleerView Answer on Stackoverflow
Solution 17 - asp.netBinoj AntonyView Answer on Stackoverflow
Solution 18 - asp.netOmer van KloetenView Answer on Stackoverflow
Solution 19 - asp.netChris PietschmannView Answer on Stackoverflow
Solution 20 - asp.netCraig McKeachieView Answer on Stackoverflow
Solution 21 - asp.netJohn SheehanView Answer on Stackoverflow
Solution 22 - asp.netJohn SheehanView Answer on Stackoverflow
Solution 23 - asp.netMRGView Answer on Stackoverflow
Solution 24 - asp.netMark CidadeView Answer on Stackoverflow
Solution 25 - asp.netRyan ShripatView Answer on Stackoverflow
Solution 26 - asp.netMRGView Answer on Stackoverflow
Solution 27 - asp.netKilhofferView Answer on Stackoverflow
Solution 28 - asp.netMark CidadeView Answer on Stackoverflow
Solution 29 - asp.netKevin GoffView Answer on Stackoverflow
Solution 30 - asp.netTylerView Answer on Stackoverflow
Solution 31 - asp.netGrahamView Answer on Stackoverflow
Solution 32 - asp.netwompView Answer on Stackoverflow
Solution 33 - asp.netfrankadelicView Answer on Stackoverflow
Solution 34 - asp.netleppieView Answer on Stackoverflow
Solution 35 - asp.netJohnView Answer on Stackoverflow
Solution 36 - asp.netKhaled MusaiedView Answer on Stackoverflow
Solution 37 - asp.netWagner Danda da Silva FilhoView Answer on Stackoverflow
Solution 38 - asp.netPauljView Answer on Stackoverflow
Solution 39 - asp.netMRGView Answer on Stackoverflow
Solution 40 - asp.netrolandView Answer on Stackoverflow
Solution 41 - asp.netcllpseView Answer on Stackoverflow
Solution 42 - asp.netCanavarView Answer on Stackoverflow
Solution 43 - asp.netAtanas KorchevView Answer on Stackoverflow
Solution 44 - asp.netDiego C.View Answer on Stackoverflow
Solution 45 - asp.netCanavarView Answer on Stackoverflow
Solution 46 - asp.netIvo SView Answer on Stackoverflow
Solution 47 - asp.netchandmkView Answer on Stackoverflow
Solution 48 - asp.netTRIVERView Answer on Stackoverflow
Solution 49 - asp.netBart VerkoeijenView Answer on Stackoverflow
Solution 50 - asp.netMichiel van OosterhoutView Answer on Stackoverflow
Solution 51 - asp.netDaveView Answer on Stackoverflow
Solution 52 - asp.netGEOCHETView Answer on Stackoverflow
Solution 53 - asp.netRameshView Answer on Stackoverflow