2012-12-20 34 views
2

我需要导航到我的城域应用程序中的互联网页面。 我的网址是(样本)'http://www.foo.com/#/foo'。 问题是LaunchUriAsync将网址切割为'http://www.foo.com'。LaunchUriAsync不会导航到正确的uri

try 
{ 
    Uri uri = new Uri(item.UriCode); 
    await Launcher.LaunchUriAsync(uri); 
} 
catch (Exception exception) 
{ 
    //TODO 
} 

我在哪里错了? 此致敬礼。

更新:

我精确该URI = http://www.foo.com/#/foo。 所以问题来自LaunchUriAsync。

+0

即使我面临这个问题。我试图用外部浏览器打开一个url,但是如果浏览器默认不是IE浏览器,它会忽略'#fragment' –

回答

0

我有相同的代码尝试了硬编码你提到 请检查下面的代码的URI:

/// <summary> 
    /// Invoked when this page is about to be displayed in a Frame. 
    /// </summary> 
    /// <param name="e">Event data that describes how this page was reached. The Parameter 
    /// property is typically used to configure the page.</param> 
    protected async override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     try 
     { 
      Uri uri = new Uri("http://www.foo.com/#/foo"); 
      await Launcher.LaunchUriAsync(uri); 
     } 
     catch (Exception exception) 
     { 
      //TODO 
     } 
    } 

输出如下所示

Launcher Test with respective URL

我认为有一些其他的问题。 可能与item.UriCode一致请检查。

+0

感谢您的回复。但硬编码不会改变这个问题。 item.UriCode具有正确的值。 – David

+0

该示例即使没有硬编码也可以工作,地址栏似乎反映了正确的URL。你有一个这种格式的真实URL的样本,我们可以尝试。 –

0

我觉得很难诊断你的例子中的错误。

看起来您正尝试导航到网页中的锚点,但是使用不正确的语法/指向不存在的锚点。但是,您的示例链接页面似乎不包含可导航锚点。

假设这是其实你正在努力实现的,可以尝试下面的例子中,你将看到导航按预期工作

Launcher.LaunchUriAsync(new Uri("http://www.hypergurl.com/anchors.html#bottom")); 

如果这不是你想达到什么样的,我会暗示URI中#字符的存在被解释为IE的锚定引用,这就是为什么你没有得到你需要的结果。

+0

我正在尝试导航到接受像http://www.foo.com/#/menu这样的导航的Flash网站。但你是对的#似乎是问题。 – David

+0

'#'后面的斜线不应该被忽略或编码? foo.com/#menu – ZombieSheep

+0

没有正确的网址是http://www.foo.com/#/menu。它正在工作。所以url不是问题。 – David