Access web.config settings from iisnode? - iisnode

If I add settings to my app's web.config file, is there an API to read the settings from my app or do I have to read the file using an XML library?

There is no special API that allows you read web.config into your node.js application running in iisnode. Having said that:
all key/value pairs from the appSettings section in web.config will be promoted to environment variables of the node.exe process, so you can access them using process.env,
as of iisnode v0.1.19, in addition to web.config, configuration settings can be specified in a iisnode.yml file; see http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html for details.
This example shows how promoted key/value pairs from the appSettings section in web.config are available as environment variables. In your web.config file:
<configuration>
<appSettings>
<add key="abc" value="test" />
</appSettings>
</configuration>
In your node application: console.log(process.env.abc); //--> test

Related

Getting error happens when the section is locked at a parent level in VIS2019 in windows 10 with IIS Express

Im using this in my web.config in my VS2019 project with IIS express on windows 10.
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
But I get this error
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
I looked at the internet to try different things, but none seem to work.
https://digitaldrummerj.me/iis-express-windows-authentication/
https://mpituley.wordpress.com/2016/10/04/http-error-500-19-in-the-iis-express/
Config Error: This configuration section cannot be used at this path
Config Error: This configuration section cannot be used at this path
Config Error: This configuration section cannot be used at this path
IIS Config Error - This configuration section cannot be used at this path
I've modified the files
C:\Users\me\Documents\project\.vs\config\applicationhost.config
C:\Users\me\Documents\IISExpress\config\applicationhost.config
I'm not sure what else to try.
Does anyone know?
Figured it out, there was another file I had to edit
C:\Users\me\Documents\project\.vs\project\config\applicationhost.config

How do I setup tnsnames.ora in asp.net core web application?

I have a small asp.net core 2.2 app that should access an oracle db; I'm using NuGet Oracle.ManagedDataAccess.Core (2.18.6), and it just works on my machine.
When I deploy it to the windows server with IIS, I place a tnsnames.ora file in app's directory and again it just works.
Now I want to use a shared tnsnames.ora file. I have tried web.config like following (recipy from StackOverflow/Google answers to similar questions).
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<!-- skipping app stuff -->
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name="tns_admin" value="F:\path\to\tnsadmin\folder" />
</settings>
</version>
</oracle.manageddataaccess.client>
</configuration>
Unfortunately, this doesn't work (and since the Core version of Oracle.ManagedDataAccess.dll doesn't have an ODPMSectionHandler class it isn't a big surprise).
So, is there a way to have a shared tnsnames.ora file with odp.net core?
(PS imo we need the odp.net-core tag)
UPDATE
One need to ensure the w3wp.exe can actually access the files.
Setting system environment variable TNS_ADMIN is a possible solution. It'll suffice in this particular case, but I'm still curious about how to configure it via web.config.
ODP.NET Core does not support config files like standard ODP.NET does. You will need to use the Configuration APIs:
https://docs.oracle.com/en/database/oracle/oracle-data-access-components/18.3/odpnt/InstallCoreConfiguration.html
With Oracle.ManagedDataAccess you don't need to use a tnsnames.ora file. In fact, you don't need an Oracle client installed on the web server. Use startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkOracle()
.AddDbContext<OracleDbContext>(builder => builder.UseOracle(Configuration["Data:OracleDbContext"]),ServiceLifetime.Scoped)
.AddDbContext<AppsDbContext>(option => option.UseOracle(Configuration["Data:AppsDbConnection:ConnectionString"]), ServiceLifetime.Scoped);
}
apsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"Data": {
"OracleDbContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zzz)(PORT=1521))(CONNECT_DATA=(zzzz)));User Id=zzz;Password=zzz;" },
"AppsDbContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=yyyy)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=yyyy)));User Id=yyyy;Password=yyyy;" }
}
}
I just ran into the same issue, strangely enough setting env variables system wide didn't seem to work. I had to configure it in the web.config itself for it to find the TNS_ADMIN, like so:
<aspNetCore ...>
<environmentVariables>
<environmentVariable name="TNS_ADMIN" value="C:\Oracle\product\11.2.0\client_1\network\admin" />
</environmentVariables>
</aspNetCore>

Variable Substitution in OctopusDeploy

I'm trying to substitute a #{port} variable during by deployment using OctopusDeploy. I am able to do it if I directly add it in my App.Config as follows:
<services>
<service name="SampleService" behaviorConfiguration="ServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:#{port}/SampleService/" />
</baseAddresses>
</host>
..
</service>
Is there a way I can add a default port here (say 25555, so that developers can use it without replacing #{port} always), but still specify to OctopusDeploy that this particular port has to be modified?
(I'm using multi-tenant deployments)
You can use the XML transform feature of config files in conjunction with Octopus deploy.
Octopus itself can run these transforms. When you compile your code, the app.config is renamed [applicationName].exe.config If you create a file called [applicationName].exe.release.config and add this to your package then you can use the same style of transform, that you would normally use in web.config transforms, in that file. If Octopus sees a file called *.release.config it will run any transforms during the deployment process.
Alternatively This blog contains instructions of extending your project so you can use the transform ability of web.config files in app.config files.
So you could do this several ways. Have the hard coded value in you "base" app.config then have the Octopus Variable as a transform in the app.release.config. When you build and package your code, so long as you use the "release" configuration the transform will fire and the hard coded value will be replaced by your build and added to the package.
Or you could do it the other way round, have the hard coded value in the app.debug.config and the Octopus Variable in the app.config. When a developer runs a debug build the Variable would be replaced by the value in the debug.config.
Octopus supports if and unless in variable substitutions (docs: http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax)
That means you could apply a default with relative ease.
Firstly, if the variable exists, use it:
#{if port}#{port}#{/if}
Secondly, if the variable does not exists, use your default:
#{unless port}25555#{/unless}
So just combine them together:
#{if port}#{port}#{/if}#{unless port}25555#{/unless}
While you create a variable using Project variable template , you have the option to provide a default value.
Check the image in the link - Shows Variable template with default value
Unless overridden the default value is substituted while deployed.
So in this case you could create a #{port} variable add the reference variable to project variable template with default value of 25555, which unless overridden will always substitute to 25555 while deployments .

servicestack hello failed to load http handler

I am following the Hello Web Service tutorial on ServiceStack.net. I get the message below when trying to access the service:
Failed to load httpHandler type `ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack'
I am using xsp which I started in my working directory for the project with the default values (i.e.: port 8080). I edited the web.config in this directory as documented in the tutorial.
How does the service find the http handler? Using xsp on port 8080 will I be able to open the metadata page?
The web.config which is in the same directory as the app contains:
<configuration>
<!-- Required for MONO -->
<system.web>
<httpHandlers>
<add path="servicestack*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<!-- Required for IIS7 -->
<system.webServer>
<!-- ServiceStack: Required -->
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
As mentioned I'm working with Mono and xsp. I now realize that in my working directory, MonoDevelop not only created web.config but also a bin directory which contains all of the dlls that I created and referenced in my project.
Setting xsp root directory to the path containing the web.config and ./bin enabled the http handler to be found and allowed me to finally access my web service and
http://localhost:8080/ServiceStack/metadata
In this scenario I did not need my dlls to be in /bin but in the project's bin
I had also overlooked the call to HelloAppHost().Init()
Bit of a learning curve... but I'm looking forward to using ServiceStack.
Thank you #mythz and #Mr.Young
I think your configuration might be incorrect. You might have mixed up the configuration with the configuration for using ServiceStack with an existing web framework.
The basic configuration for hosting ServiceStack at the root (/) path without any other web frameworks is
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
Remove the servicestack* from the path and the IIS specific stuff. It's possible your running into the VERY uncool bug in Mono ASP.NET implementation of virtual paths, details here: https://groups.google.com/d/msg/servicestack/kzfS88RldIU/LsJ2jV9M2LIJ

asp.net mvc 3 web.config connection string encryption

I have to deploy an asp.net mvc 3 website and its web.config contains database credentials.
After searching for a while, I found that one could place the connection string in a .cs file in App_Data folder, but if database password is changed, then the site needs to be recompiled.
Also I got to this link: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA , but the page says that the content is not retired.
Can someone please tell the updated practices to encrypt the connection string information in the web.config file.
Thanks.
Using an encrypt/ decrypt method on the particular web.config file
still seems to be the preferred practice
Classic implementation programmatically
I don't think the practices of encrypting web.config has updated with MVC, other than, obviously, you can't use an Event button to call the method as in the above example. You want to map the Encrypt/Decrypt methods to a controller action.
public ActionResult Encrypt()
{
ProtectSection("connectionStrings", "RSAProtectedConfigurationProvider");
return View();
}
private void ProtectSection(string sectionName,
string provider) {
Configuration config =
WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(sectionName);
if (section != null &&
!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}}
To Encrypt Connection string in Web.Config files, We can follow these steps.
Open C:\Windows\System32\CMD.exe As Administrator
In CMD type CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319 In CMD type
aspnet_regiis.exe -pef connectionStrings “Path of the Folder
containing the Web.Config file”
Ex: aspnet_regiis.exe -pef “connectionStrings” “D://PROJECTS/SAMPLE_PROJECT”
Set to identity impersonate false for project web.config
<system.web>
<identity impersonate="true" />
</system.web>
For Decryption, you can use the below command.
Open C:\Windows\System32\CMD.exe As Administrator
In CMD type CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
In CMD type aspnet_regiis.exe -pdf “connectionStrings” “Path of the Folder containing the Web.Config file”
Ex: aspnet_regiis.exe -pdf “connectionStrings” “D://PROJECTS/SAMPLE_PROJECT”
Give thubms up to my article

Resources