Friday, October 12, 2007

To terminate the console application

To terminate the console application from the code, we can use

  • Environment.Exit
  • Process.Kill

Response.Redirect inside Try Catch block throws ThreadAbortException

Making use of the Response.Redirect inside the Try / Catch block, always throws ThreadAbortException.
As a workaround we can try using Response.Redirect(URL, False) in such cases (during unavoidable situations).


Check if a column exists in a DataTable

To check if a column exists in a DataTable / DataRow
From DataTable:
dataTable.Columns.Contains("columnToBeSearched")
From DataRow:
datatRow.Table.Columns.Contains("columnToBeSearched")



Avoid multiple submits during the ongoing postback

To Avoid multiple submits during the ongoing postbacks
Just think of an ASP.Net web page that contains a button control which initiates some time consuming task. Upon clicking that button, the page submit will be initiated. In the mean time, the button will be available for further clicking. This is common in most of the heavy duty applications / web pages.
Some sort of work around that we can immediately think against this is, disabling the button control to avoid further clicks.
To achieve this,
Need to implement some JavaScript related stuffs.
1. Create a javascript function to Find and disable the specific control(s) (Button in most of the cases). The function should return “false”.

<script type="text/javascript">
function DisableControlOnSubmit()
{
var buttonToBeDisabled = document.getElementById("SubmitButton");
buttonToBeDisabled.disabled = true;
return false;
}
</script>

2. Call the function in the onsubmit event handler of the form.

<form id="form1" runat="server" onsubmit=" DisableControlOnSubmit()">

3. In ASP.Net 2.0, set the SubmitDisabledControls attribute of the
tag to true.

<form id="form1"…………………… submitdisabledcontrols="true">

4. Set the “UseSubmitBehavior” attribute of the Submit button to “false”.

<asp:Button ……………UseSubmitBehavior="false" />

Determining the Identity

Three ways for determining the Identity
  1. Page.User.Identity
  2. System.Security.Pricipal.WindowsIdentity.GetCurrent()
  3. system.Threading.Thread.CurrentPrincipal.Identity

Strong name - Third party dll / assembly

To add strong name to a third party dll / assembly , disassemble and reassemble as follows:
ildasm /out:thirdparty.dll.il thirdparty.dll
ilasm /dll /resource=thirdparty.dll.res thirdparty.dll.il /out=thirdparty.dll /key=mykey.snk

ILDASM /out:asm.il asm.dll
ILASM asm.il /KEY=key.snk /DLL /OUTPUT=asm.dll

Ref : http://www.eggheadcafe.com/forumarchives/biztalkorchestration/Jun2005/post23246643.asp


Verify, dll / assembly strong named?

To verify the strong name in assembly use,
sn -v assembly

Creative Commons License
This work by Tito is licensed under a Creative Commons Attribution 3.0 Unported License.