<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import namespace="System.Threading" %>
<%@ Import namespace="System.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat=server >
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["TestKey"] = DateTime.Now.ToLongTimeString();
Thread myThread = new Thread(new ThreadStart(DoWork));
myThread.Start();
lblTime.Text = "Page Loaded at " + Session["TestKey"].ToString();
}
}
public void DoWork()
{
System.Diagnostics.Trace.WriteLine("Working thread...");
Thread.Sleep(5000);//5 sec
throw new ApplicationException("ThrowException =true");
}
protected void btnGetSession_Click(object sender, EventArgs e)
{
lblFromSession.Text = "From Session Page Loaded at " + Session["TestKey"].ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Throw Exception test
<asp:Label ID="lblTime" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="lblFromSession" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btnGetSession" runat="server" OnClick="btnGetSession_Click" Text="Get Session" /></div>
</form>
</body>
</html>
I've posted the question to ASP.NET forums and reported to MS feedback site.
Related threads can be found here and here.
UPDATE: Microsoft replied at MS feedback site:
Some of these configuration settings are not very well documented. The setting that you would like to change is only valid in the aspnet.config file. The file is passed to CorBindToRuntimeHost when ASP.NET loads the CLR. If you make a change similar to the one below and restart the worker process, everything should work as expected.
C:\>type %WINDIR%\Microsoft.NET\Framework\v2.0.50727\aspnet.config
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
<legacyImpersonationPolicy enabled="true"/>
<alwaysFlowImpersonationPolicy enabled="false"/>
<SymbolReadingPolicy enabled="1" />
</runtime>
</configuration>