更新与C#的web.config的applicationSettings编程(MVC) [英] Update web.config applicationSettings programmatically with C# (MVC)
问题描述
我想在运行时更新Web引用地址在web.config中的applicationSettings
I want to update web reference Url in web.config applicationSettings at runtime
下面是web配置应用程序设置
Here is web config application settings
<applicationSettings>
<ItineraryBuilder.Properties.Settings>
<setting name="ItineraryBuilder_SchedulesConnectionsService_SchedulesConnectionsService"
serializeAs="String">
<value>http://www.pathfinder-xml.com/soap/*/services/SchedulesConnections</value>
</setting>
<setting name="ItineraryBuilder_SalesForceService_SforceService"
serializeAs="String">
<value>https://login.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6</value>
</setting>
<setting name="ItineraryBuilder_OAGService_CBWSPublicService"
serializeAs="String">
<value>http://ondemand.oag.com:80/CBWebServicePublic/CBWSPubliclPort</value>
</setting>
</ItineraryBuilder.Properties.Settings>
</applicationSettings>
在这里是用我的code更新
here is my code using to update
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var section = (System.Configuration.ClientSettingsSection)configuration.GetSection("applicationSettings/ItineraryBuilder.Properties.Settings");
System.Configuration.SettingValueElement sv = new System.Configuration.SettingValueElement();
sv.Equals("https://test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6");
section.Settings.Get("ItineraryBuilder_SalesForceService_SforceService").Value = sv;
configuration.Save();
但它不更新的价值,而不是移除设置值标签
But it does not update Value, instead remove Value tag from settings
早些时候,我试图更新Web服务的URL,但没有工作,所以我按照这种方法,你会请指导我如何更新Web服务URL?
Earlier i was trying to update Web service url, but did not work so i follow this approach, will you please guide me on how to update web service url?
这是我在做什么。
SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6";;
请帮忙。
推荐答案
感谢阿米拉姆Korach所有你帮
Thanks Amiram Korach for all you help
在他的帮助下,我得到了我做错了。
With his help i got what i was doing wrong.
由于他建议没有必要更新web配置,因为它不是在运行时的好办法,所以对于上述问题的解决方案是更新的Web引用,所以下面的code正常工作
As he suggested there is no need to update web config as it is not a good approach and so the solution for the above problem is updating Web reference at runtime and so the following code works fine
SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"
我在做什么错了,SF并没有传递给它创建连接使用的API类。阿米拉姆Korach帮我找到这个问题。
what i was doing wrong, the "sf" was not passed to API class which is used in creating connection. Amiram Korach helped me finding this issue.
再次感谢。
这篇关于更新与C#的web.config的applicationSettings编程(MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!