Labels

Wednesday, April 11, 2007

Change in Web.config no longer requires a restart, hence no loss of Session. Cache ...

 

Earliar in .Net1.x whenever there is any change occurs in Web.config, it results into restart of ASPNet Worker Process [aspnet_wp.exe].  This in turn results in loss of Session State, Cache …..

 

But with a quick fix in .Net2.0, we can get rid of this and freely make any changes.

 

Note: Major of the changes are required in the ‘appSettings’ section. However changes can be done in any of the sections in Web.config.

 

Fix is as below:

·         Introduce External Config files. i.e. Instead of placing the attributes of a section in Web.config, place them in an External config file and place a reference to the external file in that section of Web.config.

 

Example:

 

o        By default below is found in Web.config:

 

<?xml version="1.0"?>

<configuration>

                  <appSettings>

                        <add key="message" value="Changed" />

</appSettings>

<system.web>

<trace enabled="false" requestLimit="100" />

</system.web>

</configuration>

 

o        Introduce the concept of External Configuration as below:

 

<?xml version="1.0"?>

<configuration>

                  <appSettings configSource="appSettings.config" />

                 

<system.web>

<trace configSource="trace.config" />

</system.web>

</configuration>

 

o        Below are the individual config files.

 

appSettings.config

 

<?xml version="1.0"?>

<appSettings>

  <add key="message" value="Hello" />

</appSettings>

 

Trace.config

 

<?xml version="1.0"?>

<trace enabled="false" requestLimit="100" />

 

·         Use ‘restartOnExternalChanges’ attribute. [New in .Net 2.0]

o        This attribute is found in machine.config

o        By default value of this attribute is ‘true’.

o        But for the ‘appSettings’ and ‘system.data.dataset’, the values is set to ‘false’ in machine.config.

 

e.g.

 

<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />

 

o        For the mentioned example to work, lets us set it for ‘trace’ section also.

 

<section name="trace" type="System.Web.Configuration.TraceSection, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false"/>

 

 

 

Now make changes as below.  These changes will not result into restart and Session loss.

 

Code to change ‘appSettings’ section:

 

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");

KeyValueConfigurationCollection coll = section.Settings;

string str = coll["message"].Value.ToString();

section.Settings["message"].Value = "Changed";

config.Save(ConfigurationSaveMode.Modified);

 

 

Code to change ‘trace’ section.

 

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

TraceSection section = (TraceSection)config.GetSection("system.web/trace");

section.Enabled = !section.Enabled;

section.RequestLimit = section.RequestLimit - 5;

config.Save(ConfigurationSaveMode.Modified);

 

Note:

·         Use restartOnExternalChanges with some care, as some parameters can truly only take effect if the application restarts.

·         If you do set restartOnExternalChanges to false for a section, make sure not to cache the parameters for the section in our application, and always read values through the WebConfigurationManager.

 

 

Regards,

Arun Manglick…

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

Tuesday, April 10, 2007

HTTP PipeLine.

See the below three figures...





































1. The ASP.NET HTTP pipeline relies on IIS to receive the request.

2. When IIS receives an HTTP request, it examines the extension of the file.

3. If the file extension is associated with executable code, IIS invokes that code, in order to process the request.

4. Mappings from file extensions to pieces of executable code (.exe) are recorded in the IIS metabase.

5. When ASP.NET is installed, it adds entries to the metabase (associating various standard file extensions, including .aspx and .asmx), with a library called aspnet_isapi.dll.

6. When IIS receives an HTTP request for one of these files, it invokes the code in aspnet_isapi.dll, which in turn funnels the request into the HTTP pipeline.

7. Aspnet_isapi.dll uses a named pipe to forward the request from the IIS to an instance of the ASP.NET worker process, aspnet_wp.exe.

8. The aspnet_wp.exe worker process uses an instance of the HttpRuntime class to process the request.


Hope it is clear.....

Regards,
Arun..

Application cum Page Events ... Diagram

Below the diagrammatic representation of mixing Page-Events with Application-Events.
























This life cycle of the ASP.NET page starts with a call to the ProcessRequest() method. This method begins by initializing the page's control hierarchy.

The life cycle of Page ends by handing off the Web page's HTML markup to the Web server, which sends it back to the client that requested the page.

1

Application_Start

2

Application_BeginRequest

3

Application_AuthenticateRequest

4

Application_AuthorizeRequest

5

Application_ResolveRequestCache

6

Session_Start

7

Application_AcquireRequestState

8

Application_PreRequestHandlerExecute

Page Life Cycle occurs, and at the end generated HTML is sent to the server. This HTML is then rendered by the client/browser.

This is the place where the Page events mentioned at the right side of figure 2 occurs.

9

Application_PostRequestHandlerExecute

10

Application_ReleaseRequestState

11

Application_UpdateRequestCache

12

Application_EndRequest

13

Application_PreSendRequestHeaders

14

Application_PreSendRequestContent

Form Displays


Hope it clears the long awaited doubt...




Regards,
Arun....

How Authentication Flows... Diagrams

Reference -

http://technet2.microsoft.com/windowsserver/en/library/9e7e3daf-7500-4cb6-96b0-904ba3aec98d1033.mspx?mfr=true

http://docs.google.com/Doc?docid=df3bnbzf_240dqr5rr&hl=en


Forms Authentication:





















Windows Authentication:



















Hope it will clear the vision towards Authentication flow...

Regards,
Arun ......

Sunday, April 8, 2007

Javascript - Notifying a Parent Window when a child window is closed or terminated

Javascript - Notifying a Parent Window when a child window is closed or terminated

PARENT WINDOW

<html>
<head>
<title>Main window</title>
<script type="text/javascript">


var childWindow = null;


function openChildWindow()

{
childWindow =window.open('child.html','Childwindow','status=0,toolbar=0,menubar=0,resizable=0,scrollbars=1,top=50 ,left=50,height=375,width=650');
}


function checkChildWindowStatus()

{
if (!childWindow || childWindow.closed)

{
alert("Child window seems to be closed!");
}
}


function childWindowUnloadNotification()

{
// Here we get notification from child window. Here we can decide if the notification is
// raised because user close child window, or because user is playing with F5 key.
// NOTE: We can not trust on "onUnload" event of child window, because if user reload or refresh
// such window in fact he is not closing child. (However "onUnload" event is raised!)


setTimeout('checkChildWindowStatus()', 50);
}
</script>
</head>
<body>


Press bottom to open child window<br />
<input type="button" value="Open child window" onclick="javascript:openChildWindow();"/>
</body>
</html>

CHILD WINDOW

<html>
<head>
<title>Child window</title>
<script type="text/javascript">
function unloadNotification()

{
// Raise unload notification to parent window
window.opener.childWindowUnloadNotification();
}
</script>
</head>
<body onunload="javascript:unloadNotification();">
Body of the child window<br />
</body>
</html>

Advantages:
- Do not use polling.
- Recognize if child window is closed or is been updated by user .
- Found on IE and Mozilla Firefox.

Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice - Bridgestone - Tyre Link || Persistent Systems

Note :

There's a catch in this. If you are using any pop-up blockers for the browser, then it might create problems. I was using Google Toolbar(which had the Popup-blocker in it) and it was not allowing the Notification to be send the parent!

Friday, April 6, 2007

Hide Error Label on Body On-Load.

Below is to show how the Labels are used to show errors.

 

Declaratively we make the Label as Visible. Otherwise it won’t be accessible thru Javascript.

 

<asp:Label ID="Label1" runat="server" Text="Error Label" ForeColor="Red" Visible="true"></asp:Label>

 

But at first time the Page loads, we definitely would not like to show the error label. Hence we will make it invisible thru JavaScript using below.

 

<script language="javascript">   

        window.onload=function() {HideMe();}       

</script>

 

Now when first time the Page Loads below happens:

þ      Page_Load

þ      Page_PreRender

þ      body_onload_clientside : This hides Label again by calling above script.

þ      Page_Render

þ      Page_Unload

 

Now let’s say we have a button having an attached JS call. If JS script return true we need to call Server Side otherwise Error label should become visible,

<asp:Button ID="Outer" runat="server" OnClick="Button1_Click" OnClientClick=" return Validate();" Text="Outer" />

Below sequence fires.

  • When the button is clicked below event happens:
    • button_clientside_click :
      • If return false then the Error label will become visible and no server side event will occur.
      • If return true, then the flow will be redirected to server and below event happens.
        • Page_Load: Label gets Visible here using the declarative values.
        • Button_ServerSide_Click : Sleeps thread for 2 secs.
        • Page_PreRender
        • body_onload_clientside : This hides Label again by calling 'window.onload="Hide();'
        • Page_Render : Label gets In-Visible.
        • Page_Unload

// ------------------------------------------------
function Hide()
{
document.getElementById('Label1').style.display='none';
}

function UnHide()
{
document.getElementById('Label1').style.display='block';
}

 

function Validate()

        {

            var response=CheckValidation();

            if(response)

            {

                return true;

            }

            else

            {

                UnHide();

                return false.

            }           

        }

// ------------------------------------------------

Hope it is Clear.

 

 

Thanks & Regards,

Arun Manglick

SMTS || Microsoft Technology Practice - Bridgestone - Tyre Link || Persistent Systems

 

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

Thursday, April 5, 2007

Issues with window.onload()

Issues with window.onload()
-----------------------------

This post is to show the variations you'll found when trying to make few controls invisible on the 'OnLoad' event of body.

If you write a script as below at the Bottom, this will produce error in IE, but not in Mozilla.
But if this same script is been written at the Top, then
his will produce error in IE & Mozilla both.

<script language="javascript">
window.onload=HideMe();
</script>

Hence the solution is, write it using Inline Function as below, and place it either at top or bottom.

<script language="javascript">
window.onload=function() {HideMe();}
</script>

Below is the used HideMe() function.

function HideMe()
{
var lblLanguage=document.getElementById('labelLanguageError');
lblLanguage.style.visibility='hidden';
}

Note: You can place the window.onload() = ......,, either at the top or bottom. It does not matter.
But better to place it at the bottom.

Hope it is clear now.

Arun....