在代码(C#)中设置Facebook应用程序web.config设置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在代码(C#)中设置Facebook应用程序web.config设置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2723字,纯文字阅读大概需要4分钟。
内容图文
![在代码(C#)中设置Facebook应用程序web.config设置](/upload/InfoBanner/zyjiaocheng/653/5161057ee3ce4ed6b82e55c7b38993d8.jpg)
我正在尝试通过代码在Facebook应用程序中设置web.config设置,以避免直接使用web.config文件.
我尝试了一个自定义ConfigurationSection类,然后使用WebConfigurationManager来访问web.config文件.问题是我无法获得Configuration对象的实例.这是我的代码:
public class FacebookConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("appId")]
public string AppID
{
get { return (string)base["appId"]; }
set { base["appId"] = value; }
}
[ConfigurationProperty("appSecret")]
public string AppSecret
{
get { return (string)base["appSecret"]; }
set { base["appSecret"] = value; }
}
[ConfigurationProperty("canvasPage")]
public string CanvasPage
{
get { return (string)base["canvasPage"]; }
set { base["canvasPage"] = value; }
}
[ConfigurationProperty("canvasUrl")]
public string CanvasUrl
{
get { return (string)base["canvasUrl"]; }
set { base["canvasUrl"] = value; }
}
[ConfigurationProperty("cancelUrlPath")]
public string CancelUrlPath
{
get { return (string)base["cancelUrlPath"]; }
set { base["cancelUrlPath"] = value; }
}
public FacebookConfigurationSection()
{
}
}
以及使用该页面的页面:
protected void Button1_Click(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
FacebookConfigurationSection _config = new FacebookConfigurationSection();
_config = config.GetSection("facebookSettings") as FacebookConfigurationSection;
//FacebookConfigurationSection config = (FacebookConfigurationSection)System.Configuration.ConfigurationManager.GetSection("facebookSettings");
if (!string.IsNullOrEmpty(TextBox1.Text))
_config.AppID = TextBox1.Text.ToString();
if (!string.IsNullOrEmpty(TextBox2.Text))
_config.AppSecret = TextBox2.Text.ToString();
if (!string.IsNullOrEmpty(TextBox3.Text))
_config.CanvasPage = TextBox3.Text.ToString();
if (!string.IsNullOrEmpty(TextBox4.Text))
_config.CanvasUrl = TextBox4.Text.ToString();
_config.CancelUrlPath = "";
config.Save();
}
web.config看起来像这样(我正在尝试使用的部分):
<configSections>
<section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings" allowLocation="true" allowDefinition="Everywhere"/>
</configSections>
<facebookSettings
appId = "xxxxxxxxxxxxxxx"
appSecret = "xxxxxxxxxxxxxxxxxxxxxxxxx"
canvasPage = "xxxxxxxxxxxxxxxxxx"
canvasUrl ="xxxxxxxxxxxxxxxxxx"
cancelUrlPath = "" />
这样做给了我“对象引用未设置为对象的实例”.在_config上,它告诉我什么也没有返回.
有什么“特定于Facebook”的原因吗?
另一件事;我在代码中遇到了使用Facebook设置的这种新方法:
FacebookContext.SetApplication( IFacebookApplication )
我还没有找到一个使用此示例的好例子.
以前有没有人为此工作过?
解决方法:
只需使用
var sec = ConfigurationManager.GetSection("facebookSettings");
FacebookConfigurationSection config = (sec as Facebook.FacebookConfigurationSection);
config.AppID等
内容总结
以上是互联网集市为您收集整理的在代码(C#)中设置Facebook应用程序web.config设置全部内容,希望文章能够帮你解决在代码(C#)中设置Facebook应用程序web.config设置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。