Explicitely specify Default user credentials for Proxy Server.

Some time ago I wrote post “Call Web Services through SQuid proxy server with authentication requested”  and hoped, that I will not have more problems with Squid web proxy server.
However the solution wasn’t sufficient for other site. I’ve tried a lot of things, started thread “Unable to access external web sites through Squid proxy server with required authentication.” and posted suggestion to Microsoft “Add ability to specify credentials to defaultProxy configuration element“.


But the best solution, that I found for the moment is  to create common function to set web proxy credentials and call it  for each Web Services call,HttpWebRequest call and replace  dataset.ReadXml(url)  with HttpWebRequest.GetRequest.
The function created expects up to 4 properties in appSettings section of Web.config
        <!–Web Proxy Credentials to use if useDefaultCredentials=”true” doesn’t help


    TODO move to separate ConfigurationSection, different from AppSettings


    <add key=”ProxyUserName” value=””/>


    <add key=”ProxyUserPassword” value=””/>


    <add key=”ProxyAuthenticationType” value=”Basic”/>


    <add key=”ProxyUserDomain” value=””/>


    –>
and to be called like the following for web services




        AWSECommerceService aws = new AWSECommerceService();


         SetDefaultWebProxyCredentialsIfRequired(aws);


 


or for dataset.ReadXml


 


        IWebProxy proxyObject = CreateDefaultWebProxyWithCredentialsIfRequired(url);//WSClientHelper.


        if (proxyObject == null)


            ds.ReadXml(url);


        else


        {


            Stream strm = GetResponseStream(url, proxyObject);//HttpWebRequestHelper.


            ds.ReadXml(strm);


        }



The code of the SetDefaultWebProxyCredentialsIfRequired and other helper methods can be found here.


 

Web Browser control in MS Access form craches when Internet Explorer 7 is installed.

We have MS Access XP application that has form with embedded Web Browser control, that is used to show links.
The application was build on development machine with IE 6 installed.


  It was found that if  Internet Explorer 7 is installed on a client machine, attempt to open URL in embedded Web Browser control causes Access to crach with C0000005 error.
We came out with the simplest solution( may be not acceptable for others) to completely exclude  Access form with embedded control and  open links in the full browser, installed on client.

Search Access database source code

If you have MS Access database(or project ADP) and it is used SourceSafe for version control,

the simplest way to search VBA source code is to use Visual Studio “Search in Files” function pointed to <path>YourDatabase.scc folder.


Note that it will also search form and reports properties and controls declarations, which can be quite handy.
I am using it with Access XP.
May be, latest virsions of Access have integrated search, similar to VS.

legacyUnhandledExceptionPolicy enabled=”true” doesn’t prevent ASP.NET application restarting

We have an ASP.NET application in production(running IIS6 on Windows 2003 server) that sometimes has “.NET Runtime 2.0 Error Reporting” due to exceptions in background threads. We wanted to ignore the errors(while we will fix the cause) and specified

  <runtime>


     <legacyUnhandledExceptionPolicy enabled=true />


  </runtime>


in application web.config(as it is suggested in MSDN). Unfortunately it didn’t help- ASP.NET application still keep restarting, which causes “session expired” behavior.

I am able to reproduce this on a sample page.
On load the page saves time to Session, then started background thread, that should will exception in 5 sec.

There is also a button to read the Session value, and user can click the button.
During the first 5 sec clicking the button retrieves Session Value correctly, after 5 sec the click causes some delay.
If teh user keep clicking the button, it still continue to work (probably for a minute), then it reports that


Object reference not set to an instance of an object. – which means that session information is lost.
As I understand, after the unhandled exception is thrown, IIS starts a new working application domaiin,but keep old for a minute, than replace with the new, killing session state.


By the was, if legacyUnhandledExceptionPolicy set to false“, click after 5 sec causes a long delay and then the same error, indicating that
session state is lost, is shown.


Can we do something to ignore exceptions in background threads, as legacyUnhandledExceptionPolicy enabled=true” suppose to do?


The sample page, that I was using for testing is the following:


<%@ 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&nbsp;


        <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.NETFrameworkv2.0.50727aspnet.config
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<configuration>
    <runtime>
        <legacyUnhandledExceptionPolicy enabled=”true” />
        <legacyImpersonationPolicy enabled=”true”/>
        <alwaysFlowImpersonationPolicy enabled=”false”/>
        <SymbolReadingPolicy enabled=”1″ />
    </runtime>
</configuration>


 

If DefaultProxy address is not specified in config file, GetProxy returns unchanged URL

I found in debugger that when I am using static WebRequest.DefaultWebProxy and there is no proxy address specified in the config file,

IWebProxy.GetProxy returns the same address, as it was passed.

IWebProxy iDefaultWebProxy = WebRequest.DefaultWebProxy;

Uri uriProxy = iDefaultWebProxy.GetProxy(

I haven’t seen this in documentation, but the thread confirms the behavior.

new Uri(ws.Url));
if (sProxyUrl == ws.Url)
{
//no proxy specified
 }

Always use UrlEncode, when passing parameters to Url string

I had a function, that took the field BARCODE from the database and created URL string for Redirect with parameter ?barcode=BarcodeValue.


It worked fine for a while, because most of values were numeric or alpha-numeric.


However when  barcode has ‘plus’ sign in front, e.g ‘+2134214’, on the target page


Request.QueryString(“Barcode”) replaces the ‘plus’ sign with space and returns   ‘ 2134214’ ,which is obviously not expected


So the correct way to code is to use HttpUtility.UrlEncode , if characters such as blanks and punctuation can be used in your field, e.g.


“&Barcode=” & HttpUtility.UrlEncode(Barcode).

After fixing my code I found a very detailed article Using HttpUtility.UrlEncode to Encode your QueryStrings.

QuickCode commands file location

I was using QuickCode  on one machine and wanted to move my commands to another machine.
I didn’t find it in documentation, but I was able to find setiings file as C:Documents and SettingsMyUSERNAMEApplication DataQuickCodeQuickCode.xml.
I’ve copied the file to the different machine to the same directory and it works.

 

UPDATE: a new free 2008 version is available. See also my post “QuickCode.Net new TAB shortcut key