I have this custom section in my web.config
<defaultUserAccounts>
<userAccount email="x#x.com" password="xxx" />
<userAccount email="y#y.com" password="yyy" />
</defaultUserAccounts>
I host my web app on Azure and I want to be able to add new userAccount in the Azure App Settings.
I tried with:
defaultUserAccounts.userAccount.email / z#z.com
defaultUserAccounts.userAccount.password / zzz
OR
defaultUserAccounts:userAccount:email / z#z.com
defaultUserAccounts:userAccount:password / zzz
But it doesnt work. I can read the web.config custom section in localhost, but not when the app is hosted.
Could you help me?
You can only write the app settings using the management API of Azure. See here for an example using the Fluent SDK. Otherwise the settings are read-only from within the app.
https://stackoverflow.com/a/50116234
If you don't want to configure app setting in the Configuration you could follow this tutorial:Configure app settings configure it under tag <appSettings> in Web.config, but the values in App Service override the ones in Web.config.
The below is my test:
And use System.Configuration.ConfigurationManager.AppSettings["testkey"] to get the value, the below page is get the value with host in Azure.
Hope this could help you.
I'm currently working on a .net core application that uses a azure service bus queue.
We are restricted to using AMQP over websockets and are behind a corporate proxy.
The QuietClient class does not provide anyway to set proxy information in any of it's constructors and we get a
"Cannot connect to remote server" error when we attempt to write a message to the queue.
The exact same code works when I use it from home - not behind a proxy!
In regular .net bypassing a proxy could be achieved by adding to default proxy configuration in the web.config.
<defaultProxy enabled="true" useDefaultCredentials="false">
<proxy usesystemdefault="True" proxyaddress="http://someAddredd:8888" />
......
</defaultProxy>
Because this is a .net core application the app doesn't use a web.config file for it's configuration.
When deployed to IiS a light weight web.Config file is created to allow the IIS to integrate with core's kestrel web server. However, adding the bypass proxy info to this does not work.
Any help would be much appreciated!
I am trying to get my new asp.net core rc2 version running on my dev server that running IIs 8.5 and window 2012 server
I've followed the steps list in here, which is:
On my local:
Create a new asp.net core project using VS 2015 (Dev14) U2
Change the web.config stdoutLogEnabled="true", create a new deploy profile and publish it locally to a folder
Make sure the website works on IIS Express.
On my server
Installed the DotNetCore.1.0.0.RC2-WindowsHosting.exe and reset IIS
Setup new app pool with no managed code, setup new website in IIS that points to the local: D:\apps\myapp1\
Copy the deploy content to D:\apps\myapp1\ (such as the dll is D:\apps\myapp1\myapp1.dll)
dotnet.exe is on the path. I can even go to D:\apps\myapp1\ and dotnet myapp1.dll. It will bring up the nano server.
What I see when I hit http://mydevserver/myapp1 (or localhost/myapp1 on my dev server):
HTTP Error 502.3 - Bad Gateway
When I view the Event log, I can see a bunch of failure like this:
my logs folder on D:\apps\myapp1\logs is also empty. There is no log in that folder whatsoever.
At this point I am pretty lost on what to do. Help!!!
Here's the content of my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
</xml>
There are a few things you can do to troubleshoot:
go to the published app and try running it without IIS
logs won't be written if the folder does not exist and by default the logs folder does not exist
if it is a portable app make sure the path to dotnet.exe is on the system wide %PATH% (note you need to do iisreset after you set it to make IIS pick it up)
I wrote a blog post explaining how ASP.NET Core apps work with IIS and the post contains the section on troubleshooting your very problem.
So I finally figured out what's wrong. Apparently because I did not setup my website under "Default Web Site" of IIS, so IIS (I think) routes my website incorrectly. My fix is to move my website under Default Web Site.
One of my friends found another way to setup the website outside of Default Web Site by disabling the Default Web Site. I have not tried to get both Default Web Site enable and MyApp website enable working. Maybe somebody else can contribute in...
Following instructions here I have:
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
But connectionString is null, here is my app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="StorageConnectionString"
connectionString="DefaultEndpointsProtocol=https;AccountName=storage;AccountKey=key" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Had the same problem. Instead of using a connection string, use the configuration->appSettings->add key like this...
<configuration>
<appSettings>
<add key="StorageConnectionString" value="[ConnectionStringHere]" />
</appSettings>
</configuration>
As per documentation in MSDN http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.cloudconfigurationmanager.aspx
Only configuration settings within the appSettings tag can be read by CloudConfigurationManager. If your configuration settings are within a different tag, calling GetSetting will return Null.
Well this works, even if the comment doesn't fit, because I do have a ref to CloudConfigManager:
If you are creating an application with no reference to Microsoft.WindowsAzure.CloudConfigurationManager, and your connection string is located in the web.config or app.config as show above, then you can use ConfigurationManager to retrieve the connection string. You will need to add a reference to System.Configuration.dll to your project and add another namespace declaration for it:
using System.Configuration;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
I had the same problem. I had updated the project to use Azure SDK 2.0. I updated NuGet packages for my web and worker roles, but the Azure project in Visual Studio was still on the old version.
To fix this, Right-Click on your Azure project and select Properties. Under the Application tab, you'll see a button to Update your Azure SDK.
Make sure all your references are in synch. There's the 2012-06 library and 2012-10 Set them to Copy Local = true and verify SDK version. I dealt with the exact same thing, drove me nuts.
This happened to me when I upgraded the Azure SDK to version 2.2.
To fix it I changed the packages.config to use a newer version of the Azure ConfigurationManager.
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
Based on my understanding, I'd like to point out that CloudConfigurationManager.GetSetting will look into web.config if you're running out of a cloud service. It will look into cscfg if you're inside a cloud service.
Please refer this
link.
Following this tutorial:
You can get configuration settings like this:
RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")
I got this after upgrading Azure SDK from 2.0 to 2.2. I was able to fix by:
Right-Clicking Azure project and selecting Properties. Update Azure SDK as per the Application tab. (Thanks to rattrick's answer).
Right click to Manage NuGet Packages. On the left click Updates and update WindowsAzure.ConfigurationManager.
I had the same problem (two times).
Even after restarting Visual Studio and after restarting the Azure emulator the CloudConfigurationManager.GetSetting("SettingName") returns null.
I was sure that it has worked before and I had the latest SDK.
So the solutions was restarting my PC and after that CloudConfigurationManager.GetSetting("SettingName") returns the right value.
I got the same issue this am after revisiting my Azure solution (Web + Worker role) to update it for Azure 2.5. Reviewing the help for CloudConfigurationManager.GetSetting, if its running under a cloud platform (Azure) it reads from the ServiceConfiguration.csfg, if running as a .net web app, reads from app or web.config.
So my fix was to simply change the start up project back to the Azure cloud project, not the Web project.
I was getting null because it was hosted in the wrong platform and reading from the .config files with no settings.
(Doh!)
It is an old thread but I wanted to share my solution if issue is not resolved by above mentioned methods then make sure that Azure Storage Emulator is running when you run the application; at least for me this happened. For me I had to create a class to handle emulator issue as mentioned here...
http://blog.simontimms.com/2013/08/28/configuration-settings-in-an-azure-worker-role/
class ConfigurationProvider
{
private static string GetStorageConnectionString(string name)
{
try
{
return RoleEnvironment.GetConfigurationSettingValue(name);
}
catch (SEHException)
{
return System.Configuration.ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
}
public static string StorageConnectionString()
{
return GetStorageConnectionString("StorageConnectionString");
}
public static string DefaultConnection()
{
return GetStorageConnectionString("DefaultConnection");
}
}
I had quite similar problems. I updated from Azure SDK 2.0 to 2.2 - during this process I used the NuGet Manager to update the Microsoft.WindowsAzure.Storage to the latest. The PackageManager automatically took Microsoft.WindowsAzure.Configuration to 1.8.0.0. I was not able to get this running (it was for .Net 2.0!?). After I manually set all References to
Microsoft.WindowsAzure.Storage 2.1.0.0
Microsoft.WindowsAzure.Configuration 2.0.0.0
everything worked.
I think this is because of the way CloudConfigurationManager.GetSetting loads the assembly and calls the funktions (via reflection).
Same here after upgrading Azure SDK from 2.2 to 2.3.:
Right-Click the Azure project select Properties. In the Application tab click "Upgrade..." (Thanks to rattrick's answer).
Then there was one more error to resolve:
Trying to run the Azure Project in the Compute Emulator threw an exception:
System.Configuration.ConfigurationErrorsException was unhandled
Message: An unhandled exception of type 'System.Configuration.ConfigurationErrorsException' occurred in Microsoft.WindowsAzure.ServiceRuntime.dll
Additional information: konnte nicht erstellt werden.
In the "Error List" Window of VS2013 there was the following Warning:
Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets 1635
I let VS resolve this warning and everything worked fine.
This worked for me...
using System.Configuration;
...
var connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;
I had the same problem. None of the advices worked for me, but the "issue" was straightforward. One simple has to understand how this class works.
It does not go into your app.config / web.config or wherever you store your application settings. CloudConfigurationManager works with ServiceConfiguration.*.cscfg and ServiceConfiguration.csdef. The .csdef must contain a definition of the setting, but not its value under the ConfigurationSettings section. The settings themselves sit in .cscfg files (under the same section but including the value; I suppose the reason for the double definition is to make sure both the cloud and the local configurations have the same settings).
You can set these either by right-clicking your role in Visual Studio and selecting Properties -> Settings (in case of StorageConnectionString, simply pick "Your subscription", if your storage account is connected to the cloud service), or by editing them manually. If you mess up the settings, you'll get an exclamation mark icon.
Simple as that.
Was getting a null value with when passing a literal string as well after installing Azure SDK 2.6 (was working before).
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorage"].ConnectionString);
Replaced the literal string and it worked fine.
string connectionStr = "AzureStorage";
var connectionstring = ConfigurationManager.ConnectionStrings[connectionStr].ConnectionString;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionstring);
The deployment requirements for my app (a windows service written in C#) state the presence of a Proxy server.
From my interaction with the person who will install my app:
1. His company blocks access to internet via the proxy
2. He needs to provide the path to the proxy script in his IE Config.
3. He also needs to input a user-name/password.
My application needs to access a publicly hosted WebService. In preparation, I sent him a test Winform app. In the app.config file I used the setting mentioned in this post .NET client app: how to reach Web Services in case of proxy?
However, it did not work. I customized the proxy setting in App.config as per his IE settings, yet nothing seemed to work.
I don't want to hard-code the proxy settings in my app using the System.Net classes. There is no doubt in my mind that I want to use the config file.
So, I want to install a proxy on a VPC image and try and get my application to run.
My question:
1. What is a good proxy that I can install on my VM (windows only - no linux/squid pls.) that will replicate the behaviour that I mentioned in 2 & 3 above.
2. In case it is of interest, the proxy settings I used was:
<system.net>
<defaultProxy >
<proxy usesystemdefault= “False“ proxyaddress=“http://10.1.10.10:8080“ bypassonlocal=“True“ />
</defaultProxy>
</system.net>
Assuming that the system will read the settings from IE, I also tried
<proxy autoDetect="true" />
It did not work.
Pls. let me know if my requirements are unclear.
The open source squid proxy has Windows binaries.
If you have a Windows Server OS in you VPC, you could try out Microsoft's very own ISA Server. There's a 180-day trial version here.