I am using MSMQ in C#, how can i set queuepath in web.config?
Any suggestions?
Thanks
Add an appSetting key with the path of your Queque ?
<appSettings>
<add key="myquequepath" value="FormatName:DIRECT=OS:machinename\private$\MyQueue" />
</appSettings>
It was really simple i found solution.
<add key="MSMQName" value=".\private$\WebSiteEmails"/>
Related
Here is my appsettings
<appSettings>
<add key="webpages:Enabled" value="true" />
<add key="K1" value="Debendra Dash"/>
</appSettings>
Here is how i am trying to read in my controller:
string x = System.Configuration.ConfigurationManager.AppSettings["K1"];
And am getting null always.
Here is my web.config.
Your code is correct.
Try a couple of things
See if you're editing the correct Web.config.
Try using WebConfigurationManager instead of ConfigurationManager
There are a lot of questions like this and I've checked them out all.
Firstly, I checked the app.config's path using
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
to make sure code looking for the right app.config file.
After making sure of that, I still dont know why ConfigurationManager.AppSettings["BaseURL"]; is returning null. Any ideas?
Edit:
<appSettings>
<add key="BaseURL" value="blabla" />
</appSettings>
Answer Edit: Next time do not be like me and overwork your brain. You may forget you are working at a Virtual Machine, not at your desktop. In short, this is another "looking at the wrong place" question.
Just try this
Use WebConfigurationManager instead of using ConfigurationManager
Example :
Place below code in your web.config
<appSettings>
<add key="BaseURL" value="blabla" />
</appSettings>
and
To get the value use the WebConfigurationManager like below
string base_url= WebConfigurationManager.AppSettings["BaseURL"].ToString();
I use System.Configuration.ConfigurationManager.AppSettings["key1"] in settings.designer.cs file. It's working fine in the development but after I moved all the .dll files into production it is not working.
In web.config file I added app settings in development and production both. What is the problem?
Code from settings.designer.cs file
get
{
return WebConfigurationManager.AppSettings["ConnectionString"];
//return (AppSettings["ConnectionString"]);
//return ((string)(this["ConnectionString"]));
}
I tried all three return statements. 3rd return is working fine in both dev & prod but it is not rendering from web.config.
Code in web.config
<add key="ConnectionString" value="connection string values are given here">
Don't use WebConfigurationManager.
Use System.Configuration.ConfigurationManager.AppSettings["key"] instead to read key-value pair kept in Web.config, e.g.:
<configuration>
<appSetttings>
<add key="key1" value="value1" />
</appSetttings>
</configuration>
and System.Configuration.ConfigurationManager.ConnectionStrings["name"].ConnectionString to read connection string, e.g.:
<configuration>
<connectionStrings>
<add name="name" connectionString="value1" />
</connectionStrings>
</configuration>
You have to add configuration setting (connectionstring) to last execution program config file.
Is it possible to transform the following Web.config appSettings file:
<appSettings>
<add key="developmentModeUserId" value="00297022" />
<add key="developmentMode" value="true" />
/* other settings here that should stay */
</appSettings>
into something like this:
<appSettings>
<add key="developmentMode" value="false" />
/* other settings here that should stay */
</appSettings>
So, I need to remove the key developmentModeUserId, and I need to replace the value for the key developmentMode.
You want something like:
<appSettings>
<add key="developmentModeUserId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
<add key="developmentMode" value="false" xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"/>
</appSettings>
See Also: Web.config Transformation Syntax for Web Application Project Deployment
Replacing all AppSettings
This is the overkill case where you just want to replace an entire section of the web.config. In this case I will replace all AppSettings in the web.config will new settings in web.release.config. This is my baseline web.config appSettings:
<appSettings>
<add key="KeyA" value="ValA"/>
<add key="KeyB" value="ValB"/>
</appSettings>
Now in my web.release.config file, I am going to create a appSettings section except I will include the attribute xdt:Transform=”Replace” since I want to just replace the entire element. I did not have to use xdt:Locator because there is nothing to locate – I just want to wipe the slate clean and replace everything.
<appSettings xdt:Transform="Replace">
<add key="ProdKeyA" value="ProdValA"/>
<add key="ProdKeyB" value="ProdValB"/>
<add key="ProdKeyC" value="ProdValC"/>
</appSettings>
Note that in the web.release.config file my appSettings section has three keys instead of two, and the keys aren’t even the same. Now let’s look at the generated web.config file what happens when we publish:
<appSettings>
<add key="ProdKeyA" value="ProdValA"/>
<add key="ProdKeyB" value="ProdValB"/>
<add key="ProdKeyC" value="ProdValC"/>
</appSettings>
Just as we expected – the web.config appSettings were completely replaced by the values in web.release config. That was easy!
If you want to make transformation your app setting from web config file to web.Release.config,you have to do the following steps.
Let your web.config app setting file is this-
<appSettings>
<add key ="K1" value="Debendra Dash"/>
</appSettings>
Now here is the web.Release.config for the transformation.
<appSettings>
<add key="K1" value="value dynamicly from Realease"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"
/>
</appSettings>
This will transform the value of K1 to the new value in realese Mode.
I do not like transformations to have any more info than needed. So instead of restating the keys, I simply state the condition and intention. It is much easier to see the intention when done like this, at least IMO. Also, I try and put all the xdt attributes first to indicate to the reader, these are transformations and not new things being defined.
<appSettings>
<add xdt:Locator="Condition(#key='developmentModeUserId')" xdt:Transform="Remove" />
<add xdt:Locator="Condition(#key='developmentMode')" xdt:Transform="SetAttributes"
value="false"/>
</appSettings>
In the above it is much easier to see that the first one is removing the element. The 2nd one is setting attributes. It will set/replace any attributes you define here. In this case it will simply set value to false.
Can someone explain what ServicePointManager.FindServicePoint is intended to be used for? I have been writing some code to work with proxies in C#, and have seen indicators that it might be useful in this respect, but can't see why or how. How is this class (ServicePointManager) or method (ServicePointManager.FindServicePoint) supposed to be used (or when)?
Thanks.
The ServicePointManager.FindServicePoint(...) method will help you get the ServicePoint object that you've been specified in the configuration file.
Let's say, this is your configuration file:
<configuration>
<system.net>
<connectionManagement>
<add address="http://www.contoso.com" maxconnection="2" />
<add address="192.168.1.2" maxconnection="4" />
<add address="*" maxconnection="1" />
</connectionManagement>
</system.net>
</configuration>
This code would retrieve the "http://www.microsoft.com" ServicePoint:
ServicePoint sp1 = ServicePointManager.FindServicePoint(new Uri("http://www.microsoft.com"));
You can read all about it here.