locked
XBAP Has trouble behind a proxy server RRS feed

  • Question

  • I am deploying an app for an enterprise customer.  They are behind a proxy server, trying to access the xbap on the WWW.

    While the xbap opens and starts up fine, anytime the xbap tries to access another file at the site of origin, it does not work for them.  It works everywhere else though.  The client computer has .NET Framework 3.5 SP1.

    I have tried accessing files using Application.GetRemoteStream, which fails silently behind the proxy (returns null).  Also I have tried
     new WebClient().DownloadString(myURL); 
    Which fails with the error:

    system.net.webexception:  The remote server returned an error: (407) Proxy Authentication Required.


    I really need to get this working.  I am assuming there is a solution that can be made on the XBAP side, not requiring any reconfiguration of the proxy server itself. 


    Thursday, September 10, 2009 7:29 PM

Answers

  • The machine.config change works.  And it appears there is a hotfix:  http://support.microsoft.com/default.aspx/kb/917952/en-us
    Does anyone know what the hotfix actually does?  Does it just change the machine.config file?


    • Marked as answer by Hua Chen Thursday, September 17, 2009 9:23 AM
    Friday, September 11, 2009 9:07 PM

All replies

  • Check these threads:
    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/94b455b9-488b-457a-a3a3-13c87e02cabe
    http://geekswithblogs.net/technetbytes/archive/2007/08/11/114573.aspx

    You can always as the user for authentication on first access and set:
    Proxy.Credentials = New System.Net.NetworkCredential("user", "password", "domain")
    Domain is not mandatory.
    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é... http://bigsby.eu
    • Edited by Bigsby Thursday, September 10, 2009 8:18 PM Upgrade
    Thursday, September 10, 2009 8:12 PM
  • Bigsby, I get a bunch of permission exceptions trying any of those routes.  My XBAP is running (purposefully so) in Partial Trust.

    I tried this:

    IWebProxy proxy = new WebProxy();
    proxy.Credentials = new NetworkCredential(tbUser.Text, tbPassword.Text);

    client.Proxy = proxy;

    String s = client.DownloadString(myurl);


    I get the error "Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." on the line "client.Proxy=proxy".
    Thursday, September 10, 2009 8:44 PM
  • So I am assuming this is a bug with xbaps. 

    The default credentials should be applied to this request using either method (GetRemoteStream and WebClient.DownloadString), but from an xbap the credentials are not used.  It also seems that from the partial trust XBAP, I cannot set the credentials.  If I do, I get WebPermission exception.

    This is a massive problem.  How are xbaps supposed to function in a corporate environment behind a proxy?

    Friday, September 11, 2009 6:06 PM
  • I don't think calling an external security feature a bug is that correct. Never the less. Seek and you shall find.

    Have you tried to just set WebClient.UseDefaultCredentials to true? Its default value is false.

    Check this too:
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d6b018bf-df4c-4cf8-90db-98e502d619e6

    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é... http://bigsby.eu
    Friday, September 11, 2009 6:18 PM
  • Bigsby, thanks for your reply.

    I tried
    WebClient.UseDefaultCredentials = true;

    but it fails with the following Exception:

    System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.Net.CredentialCache.get_DefaultCredentials()
       at System.Net.WebClient.set_UseDefaultCredentials(Boolean value)
       at GetRemoteStreamTest.Page1.Button_Click(Object sender, RoutedEventArgs e)
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.EnvironmentPermission
    The Zone of the assembly that failed was:
    MyComputer


    I will try the machine.config file change.  But that doesn't seem like a tenable solution, as asking my users to go manually change a .NET configuration file would defeat the whole purpose of the app being in partial trust.
    Friday, September 11, 2009 7:17 PM
  • The machine.config change works.  And it appears there is a hotfix:  http://support.microsoft.com/default.aspx/kb/917952/en-us
    Does anyone know what the hotfix actually does?  Does it just change the machine.config file?


    • Marked as answer by Hua Chen Thursday, September 17, 2009 9:23 AM
    Friday, September 11, 2009 9:07 PM
  • The exe is not Reflectable so I can't tell.

    You might get that answer if you ask in the Discussions tab.
    Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é... http://bigsby.eu
    Saturday, September 12, 2009 9:42 PM