Relative path configuration in appsettings.json in .NET Core - .net-core

For sake of simplicity lets say we have the following structure of configuration files where I load all of them:
c:\apps\myapp\appsettings.json
c:\apps\appsettings.json
c:\appsettings.json
The configuration "schema" looks like this:
{
"logPath": "c:\\apps\\logs"
}
Instead of giving absolute path of log folder, I would like to give relative one like .\\logs where . would be current configuration file. While debugging I discovered that IConfigurationRoot contains all those configuration sources (in this case JsonConfigurationSource) which contains path to configuration file, but I didn't find any way how to get ConfigurationSource for specific key. So Something like IConfigurationRoot.GetConfigurationSource(string key).
Is there any way how to get configuration source for specific key? Or maybe some other way to use relative paths?

Related

Is there a way to serve a directory using map local and Charles?

I have a network request in the form of:
http://www.blahblah.com/folder/version/dist
I would like to add a rule to the Map Local option in Charles, in order to serve a directory that looks like:
Users/me/Documents/code/project/dist
The file structure of both dist folders are the same. My current request rule is: http://www.blahblah.com/folder/*/dist, and I'm asking it to serve Users/me/Documents/code/project/dist in its place, however, the files still come from the original requested resource.
Is there a way to proxy a whole directory?
You should be able to do so, by what is said in the CharlesProxy documentation:
If you are testing css, swf or image changes you can map those file types to your local development copy of the website so you can browse the live site with all your development assets. Create a mapping from live.com/*.css to the root of your local development copy, and similar mappings for the other file types. Alternatively you can map whole directories or individual files as required.
I guess your problem might be on the path where you are trying to map from. I would say you need to add an asterisk at the end of your path, something like:
http://www.blahblah.com/folder/*/dist/*
You can try to add the .css as done in the example
http://www.blahblah.com/folder/*/dist/*.css

Need to get real path to the Servlet i'm using. JAVA

I need to get path to the servlet that i'm using inside of it. With some searchings i found something like this:
System.out.println(getServletContext().getRealPath("/"));
and the result is:
C:\Users\me\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ProjectName\ServletName
tbh i dont know what does ".metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps" mean, i just want to get path to the "original" project which is:
C:\Users\me\workspace\ProjectName\ServletName
is there any way to get this path directly(without getting the big path first and then cutting the middle part of it)?
The result you get is the location of the servlet .class file. Eclipse deploy your application in your server applications folder .metadata/.plugins/.../wtpwebapps (because you use the temporary folder which is different from your real Tomcat location), after invoking the function getRealPath("/"), your servlet has been deployed in the server and it has not been executed from it's original location. Even if you change tomcat's directory, you'll always get the location of the deployed servlet and not the .java file.
read more about Server temporary location.
you can also use ${pageContext.request.contextPath}.This command point the root folder of the project.

Create Assemblies with Additional Files To Store data files in a relative path to the referenced assembly

According to U-SQL reference about CREATE ASSEMBLY statement:
https://msdn.microsoft.com/en-us/library/azure/mt763293.aspx
When we include additional files with the assembly from the store, we can definitely define a relative path for each file in the store we are referring to, however, what if we want to locate it in a relative path that other dlls are expecting while executing.
Example :
CREATE ASSEMBLY BusinessLogic FROM #"/Path1/BusinessLogic.dll"
WITH ADDITIONAL_FILES =
(
#"/Path1/Path2/dataFile.xml",
)
Now while BusinessLogic.dll is running, it's expecting dataFile.xml to be in relative directory /Path2, which is not preserved in the runtime (knew that from local debugging), and thus the whole execution fails, how to preserve this relative path for additional files ?
As the documentation you refer to explains, the additional files are being placed into the working directory at the location without a directory right now:
This clause optionally specifies the name that is used for the additional file, when it is placed into the runtime working directory. The string literal has to be a valid filename (and not contain a path) or an error is raised. Note that this should the name of the file that the main assembly will be using to refer to the file or the assembly code will fail to find the file at runtime and raise an error.
So folder structures are currently not preserved. What can you do?
Please file a feature request to support relative path names in the additional file AS clause.
You can deploy the files inside a ZIP file and then unzip them inside your custom assembly to get them to the right place.

accessing resource file in vendors bundle

I have a Symfony2 bundle which contains some wsdl files in Resources directory. It forces me to define some additional entries in config file like:
parameters.fx_wsdl = '../vendor/project-name/bundleName-bundle/vendorName/xxxBundle/Resources/confid/ws/fx.wsdl'
yeach, as you see it looks ugly. Is there a way to define it as:
parameters.fx_wsdl = 'VendorNameBundleNameBundle/Resources/confid/ws/fx.wsdl'
any object which can translate VendorNameBundleNameBundle into ../vendor/project-name/bundleName-bundle/vendorName/xxxBundle automatically

Umbraco - Get Directory of Config Files

I'm working with Umbraco 4.7.1 and I've created some extensions that hook into Document.AfterPublish and Document.AfterUnPublish. I need to find the directory of the config files from here, but need to be independent of server installation (i.e. a literal won't work). Is there any way of finding this at that point in time?
I think what you are looking for is the umbraco.IO.SystemDirectories class, specifically the Config property.
This will return "~/config" by default, but can be overridden by adding a umbracoConfigDirectory key to the appSettings section of the web.config file and specifying a different path there.

Resources