Can AzureReader2 read Azure storage configuration settings from the service config rather than the web.config? - imageresizer

Is there any way for the AzureReader2 plugin to read its connection string and endpoint config values from the service config file rather than just the web.config?
The problem is that we build Azure package files (.cspkg) and web.config files are embedded within the package. Therefore we strive to keep our web.config files constant across all different deployments (test, dev, and production). We normally deploy using a package file and a service config file.

Install AzureReader 2 via code during application startup instead, and you can pass it the connection string directly:
var nvc = new NameValueCollection();
nvc["endpoint"] = "http://127.0.0.1:10000/devstoreaccount1/";
nvc["connectionString"] = "UseDevelopmentStorage=true";
new AzureReader2Plugin(nvc).Install(Config.Current);

Related

How to transform connection strings in app.config

I am working on the CI/CD pipeline for a quite big project that was created 3 years ago and it is a asp.net core 2.1 (.NET Framework) project. This project store the connection strings in app.config file for EF 6.
I was trying to create Web Deploy Package for this project, but VS cannot detect the connection string in app.config, I have tried to create custom Parameters.xml file
<parameter name="OptagEntities-app.config Connection String" description="doesn't matter" defaultvalue="__OptagEntities__" tags="">
<parameterentry kind="XmlFile" scope="\\app.config$" match="/configuration/connectionStrings/add[#name='OptagEntities']/#connectionString">
</parameterentry>
I have tried to deploy this project to local IIS and I can see that connection string is not updated from the value in SetParameters.xml file. We have on premise TFS server and same flow works for webform project. The different is Web config and this project is using app.config, because asp.net core .NET framework only create web.config when publish.
I know I can use appsetting.json to transform the different the ENV, but it require code changes and worsting thing is that this project is referencing another project via nuget that also using a connection string in app.config.
Any work around for this?
I use the code blow to change the EF6 connectionstring at runtime, "myConnectionStrings" can load from appsettings.json
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
connectionStringsSection.ConnectionStrings["Entities"].ConnectionString = "myConnectionStrings";
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");

How to have a config file for local development and one for the development server in AspNet Core without breaking the IsDevelopment function logic

With AspNet Core, I would like to have a different config value when I develop a web site on my local computer and when the web site is published on the development server.
For exemple, on my computer, the log files use the path "..\..\logs\app.log" and on the development server it's "w:\logs\app.log". Since that by default, AspNet Core is using the appsettings.Development.json file wherever I'm on my development computer or on the development server, I cannot set the path differently.
So how can I distinguish when the code run on my local computer and when it run on my development server and have a different settings in my appsettings.json files and still use env.IsDevelopment() that will return true on both environment? The reason I need that is because Microsoft use the IsDevelopment() function in there own logic and I don't want to break that.
.NET Core solves this problem by using "Environments".
It's kind of evolved over the versions so it's a little different depending on which version of .NET Core you are actually using. But in short, your code will typically load appsettings.json first, then overwrite any settings from a file called :
appsettings.{env.EnvironmentName}.json
Notice how the Environment is suffixed to your appSettings. To set the environment for your machine, if you are on Windows you can run a powershell command like :
$Env:ASPNETCORE_ENVIRONMENT = "Development"
Or have a quick google around "How to set environment variables". As long as the key is "ASPNETCORE_ENVIRONMENT", then whatever you set it to, you can then load that file as your settings.
More info : https://dotnetcoretutorials.com/2017/05/03/environments-asp-net-core/
From your description, I understood that you want to keep single Config file. If that is the case, you can alter your configuration setting on server side using environment variables.
Logging__logPath=C:\dir\file.log
this link may help you https://medium.com/thirddev/overriding-configuration-using-environmental-variables-in-asp-net-core-d38079475654
If your server is hosted on IIS then you can change your environment variables under Configuration Editor. Here is the step by step instructions
Go to your application in IIS and choose Configuration Editor.
Select Configuration Editor
Choose system.webServer/aspNetCore (RC2 and RTM) or system.webServer/httpPlatform (RC1) in Section combobox
Choose Applicationhost.config ... in From combobox.
Click on enviromentVariables element and open edit window.
Set your environment variables.
Close the window and click Apply. Done
REF: https://stackoverflow.com/a/36836533/1118978
Visal demonstration:
https://www.andrecarlucci.com/en/setting-environment-variables-for-asp-net-core-when-publishing-on-iis/
If you prefer to have multiple config files, then :
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
and environment variable is needed to be set ASPNETCORE_ENVIRONMENT=DevServer and your config file will be appsettings.DevServer.json

NServiceBus endpoint is not starting on Azure Service Fabric local cluster

I have a .NetCore stateless WebAPI service running inside Service Fabric local cluster.
return Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
When I'm trying to start NServiceBus endpoint, I'm getting this exception :
Access to the path 'C:\SfDevCluster\Data_App_Node_0\AppType_App10\App.APIPkg.Code.1.0.0.diagnostics' is denied.
How can it be solved ? VS is running under administrator.
The issue you are having is because the folder you are trying to write to is not supposed to be written by your application.
The package folder is used to store you application binaries and can be recreated dynamically whenever an application is hosted in the node.
Also, the binaries are reused by multiple service instances running on same node, so it might compete to use the files by different instances.
You should instead instruct your application to write to the WorkFolder,
public Stateless1(StatelessServiceContext context): base(context)
{
string workdir = context.CodePackageActivationContext.WorkDirectory;
}
The code above will give you a path like this:
'C:\SfDevCluster\Data_App_Node_0\AppType_App10\App.APIPkg.Code.1.0.0.diagnostics\work'
This folder is dynamic, will change depending on the node or instance of your application is running, when created, your application should already have permission to write to it.
For more info, see:
how-do-i-get-files-into-the-work-directory-of-a-stateless-service?forum=AzureServiceFabric
Open folder properties Security tab
Select ServiceFabricAllowedUsers
Add Write permission

Programmatically configure and host WCF Service in IIS

How can i programmatically configure and host WCF Service in IIS. I have created my WCF service example /WCFServices/Service1.svc". I want to programmatically configure and host this service in IIS. Can anyone help me on this?
The class you want is Microsoft.Web.Administration.ServerManager
http://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager(v=VS.90).aspx
It has methods for manipulating most aspects of IIS, for example, adding application pools and applications. for example, this code configures a new IIS application
//the name of the IIS AppPool you want to use for the application - could be DefaultAppPool
string appPoolName = "MyAppPool";
//the name of the application (as it will appear in IIS manager)
string name = "MyWCFService";
//the physcial path of your application
string physicalPath = "C:\\wwwroot\mywcfservice";
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = sitesCollection[0];
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement applicationElement = siteCollection.CreateElement("application");
applicationElement["path"] = name;
applicationElement["applicationPool"] = appPoolName;
ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement["path"] = #"/";
virtualDirectoryElement["physicalPath"] = physicalPath;
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement);
serverManager.CommitChanges();
}
In general, the calss is just a thin wrapper around the IIS config file. You can understand it by looking at your exisiting file, or even by looking at what you have to do in IIS Manager to configure the service manually, then translating that into the resulting configuration changes.
You can do all (at least lots of) the the IIS configuration in this way (e.g. configure application throttling, enable authentication schemes etc.).
The WCF part of the configuration is just normal WCF. you can do it either in code or in configuration.
What you are looking for is called Publish. You can find it from the right-click context menu on the WCF Service project. You can publish from there or create a package for publishing later or distributing it to a remote site. There are a lot of tutorials on the net.
If you have a specific question about this feature, feel free to ask.
Have a look at msdeploy, a command line packaging and deployment tool:
http://blogs.iis.net/msdeploy/
http://vishaljoshi.blogspot.de/2009/02/web-deployment-with-vs-2010-and-iis.html
http://msdn.microsoft.com/en-us/vs2010trainingcourse_webdevelopment_topic8#_Toc282089433

update wsdl file in web service task in SSIS dynamically

i am trying to develop an SSIS package with web service task, i have specified the service url
http://localhost/myservice.asmx?wsdl in the connection manager and configured the location of wsdl using expressions
but when i deploy the package to a prod environment, SSIS package will be on a DB server and web service will be hosted on a different server, which means i need to change the service url in the dtsConfig file.
but the problem i am facing is when i change the connection string url in dtsConfif file it will not update the wsdl file, and it points to old url and package fails with 404 error
If I understand, you are changing a value in the dtsConfig, but your SSIS package is not picking up on the new value. Are you sure it is looking at the updated dtsConfig file when it runs?
You should have, for example, a SQL Server Agent Job that is executing your SSSI package, and it should be pointing to the updated configuration file; or else, the Job should override the configured values. You can try different ways to set the url string to the desired destination.