Even a chimp can write code

Friday, May 19, 2006

Passing URL parameters to a WPF browser application

A colleague asked:
I have a task on my plate to change the StartURI for our app based on query parameters to the xbap app. Is that possible?

We have one app (which combines Foo and Bar), but when users launch "myapp.xbap?view=Bar", I’d like to show a different initial UI.

[ed: minor edits made to the quote above to remove specificity]

So, can you pass in URL parameters to a WPF browser application (.XBAP)? Sure you can. However, only if the XBAP is deployed over HTTP. You cannot launch an app from a UNC share and expect to pass it HTTP request parameters.

Here's how: You need to specify <TrustUrlParameters>true</TrustUrlParameters> in the project file and use System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri property to get to the URL and pull the request parameters from it.

This functionality will not be available when you run the app within Visual Studio (i.e. hitting F5 or Ctrl-F5) because WPF applications launched from within Visual Studio are not ClickOnce-deployed.

Tags:

Email this | Bookmark this

4 Comments:

  • Can you pass URL param to loose xml page?

    By Anonymous Anonymous, at July 23, 2006 at 8:56 AM  

  • Unfortunately there isn't support in loose XAML to get to the activation URI (and by extension to the request parameters). We're looking at solving this in a future version.

    By Blogger Ashish Shetty, at July 25, 2006 at 12:25 PM  

  • Do you have to publish the site to get the URI?

    Can you do it by opening C:\project.xbap?

    By Anonymous Anonymous, at August 10, 2007 at 12:13 PM  

  • I am trying to pass the binary string which represents a .png file to an xbap. The length of this file is longer than is usually allowed by a query string. So is there another way to pass parameters to an xbap?

    Thanks.

    By Anonymous Anonymous, at July 13, 2008 at 10:22 PM  

Post a Comment | Home | Inference: my personal blog