Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 脸谱网-“;像这样";asp页面中的url问题_Asp.net_Facebook - Fatal编程技术网

Asp.net 脸谱网-“;像这样";asp页面中的url问题

Asp.net 脸谱网-“;像这样";asp页面中的url问题,asp.net,facebook,Asp.net,Facebook,我将facebook“喜欢这个”小部件放在我的页面上,我遇到了一个问题: 我的url是使用以下方法动态构造的: protected String getCurrentUrl() { return Server.HtmlEncode(Request.Url.AbsoluteUri); } 因此,facebook iframe是: <iframe src="http://www.facebook.com/plugins/like.php?href=<%= getCurrentU

我将facebook“喜欢这个”小部件放在我的页面上,我遇到了一个问题:

我的url是使用以下方法动态构造的:

protected String getCurrentUrl()
{
    return Server.HtmlEncode(Request.Url.AbsoluteUri);
}
因此,facebook iframe是:

<iframe src="http://www.facebook.com/plugins/like.php?href=<%= getCurrentUrl() %>&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=80"
scrolling="no" frameborder="0" style="border: none; overflow: hidden; width: 450px;
height: 80px;" allowtransparency="true"></iframe>

getCurrentUrl结果的一个示例是:

但是,由于这些“&”(&-编码时)facebook无法正确获取链接:

  • 需要:

而不是上面的全部…所以它在第一个&


您看到任何解决方法了吗?

您可能希望Url编码:

return Server.UrlEncode(Request.Url.AbsoluteUri);
尽管我建议您使用以下内容生成此url:

public string GetFaceBookAddress()
{
    var builder = new UriBuilder("http://www.facebook.com/plugins/like.php");
    var nvc = new NameValueCollection
    {
        { "href", Request.Url.AbsoluteUri },
        { "layout", "standard" },
        { "show_faces", "true" },
        { "width", "450" },
        { "action", "like" },
        { "font", "verdana" },
        { "colorscheme", "light" },
        { "font", "80" },
    };
    builder.Query = ToQueryString(nvc);
    return builder.ToString();
}

private static string ToQueryString(NameValueCollection nvc)
{
    return string.Join("&", Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(nvc[key]))));
}
然后:

<iframe src="<%= Server.HtmlEncode(GetFaceBookAddress()) %>" ...

您可能需要Url编码:

return Server.UrlEncode(Request.Url.AbsoluteUri);
尽管我建议您使用以下内容生成此url:

public string GetFaceBookAddress()
{
    var builder = new UriBuilder("http://www.facebook.com/plugins/like.php");
    var nvc = new NameValueCollection
    {
        { "href", Request.Url.AbsoluteUri },
        { "layout", "standard" },
        { "show_faces", "true" },
        { "width", "450" },
        { "action", "like" },
        { "font", "verdana" },
        { "colorscheme", "light" },
        { "font", "80" },
    };
    builder.Query = ToQueryString(nvc);
    return builder.ToString();
}

private static string ToQueryString(NameValueCollection nvc)
{
    return string.Join("&", Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(nvc[key]))));
}
然后:

<iframe src="<%= Server.HtmlEncode(GetFaceBookAddress()) %>" ...

@Christian,请查看我关于使用改进函数建议的更新。@Christian,请查看我关于使用改进函数建议的更新。