File access in Net Core running on Full Net Framework - asp.net-core

I have a net core app now running on full net452 framework. I have included a file (test.txt) in wwwroot that needs to be accessed from the net452 libraries. I have injected the hosting environment and gotten the path. However, System.IO.File.Exists(path\filename) returns false and the dll code returns "Specified file does not exist." The file does exist and the path "C:\Users\bbrown\Source\Repos\MyRepo\wwwroot\test.txt" looks correct. I am 99% certain that it is a permissions problem. A straight net452 app with path of "C:\Users\bbrown\Documents\TestApp\AppData\test.txt" works.
How can I gain access to the file or at least debug the problem.
Thanks!

1) Make sure you have proper permission for that folder. Go to that folder under security and see if you have permission or not. If you are using IIS then make sure that your application pool user has a permission on that folder.
2) _hostingEnvironment.ContentRootPath will give you the content root path which means the folder itself. You should use _hostingEnvironment.WebRootPath which will give you the path of wwwroot folder.
Here is the nice blog that will clear your doubts
https://blog.mariusschulz.com/2016/05/22/getting-the-web-root-path-and-the-content-root-path-in-asp-net-core

Related

How can I get to the root folder of another project in a .NET Core solution?

I need to read the settings file (appsettings.json) from another project in my solution. When I use:
Directory.GetCurrentDirectory()
From within the current project, I get the following path:
{projectRootFolder}\bin\Debug\netcoreapp3.0\
My question is: How can I get to the exact same folder in another project in the same solution? Or is there a better way to access the settings file from another project within the current solution?
If I understand the problem correctly there are two misconceptions:
It has little sense to access output directory of an another project as the structure has sense in compile time only. You will not have the same structure in run-time once the application is "published".
The Directory.GetCurrentDirectory() returns the current working directory. It is just a coincidence to be set to project output directory by Visual Studio. It can be totally different directory.
It is not clear to me what exactly you are trying to achieve. I recommend using the configuration system provided by .net core to access the configuration and add that other appsettings.json as another configuration provider.
If you really need to open the settings file then the project with the settings file (A) should mark the file as "Copy to Output Directory" and the project to open the file (B) should reference the project A. So the settings file will be copied to output of the project A too.
What you're attempting to do is not possible. There's no inherent way for ASP.NET Core to know where a totally different app running in a totally different process is located.
If you need to access appsettings.json from another project, then you would need to include it as a linked file in your project, and set it to copy to output. Then, you're accessing it actually from your project (which is all you can do), but the file itself is shared.
However, this is almost always a bad idea, and usually a sign that you're doing something wrong. If you truly do need to share the settings, then what you should be doing is putting them in a distributed config provider like Azure Key Vault or similar, where both projects can independently access the settings from a common store.

unable to include external files in a project

I have created the default play application in IntelliJ in directory P. I have over-written the default index.scala.html with my own html code. The html code refers to some css and js files which are outside the directory P. To include these external files, I added the directory of these files using project configuration settings.
My webpage doesn't load properly as the server returns 404 for the css and js files. What am I doing wrong?
When you added your directory using project structure, you only say:
Hey, IDEA, please consider this folder part of my project, consider
its contents source code and display it when I open my project.
However, when you deploy or run your app, you only deploy the usual folders to the server, which contain the resources which will be available for clients to access.
The external directory is not part of these directories and will not be deployed.
What you can do is to copy the file from the external directory as a part of your build process before deploying the application.
EDIT: Detailed answer here: What is intellij's build process for play applications

How to set write permission to a single file in WiX

I have an MVC app and I need to set write permission to Everyone on a single file.
The file is generated on the fly during installation by a custom action script. The file itself is created inside the app folder.
I know the final path of the file, after the installation process
Online I've seen only examples for setting permission to folders and subfolders, none of them seemed to address my issue

Where should the files referred from GlassFish server 3.0 web app reside?

I have deployed my web application in GlassFish server 3.0. When I execute it, I get an error: The system cannot find the file specified (MobileOntologyRev1.owl) , which is a file from which I read in my code (I haven't specified the absolute path for this file in my code, and simply refer it using the file name without any addtional path) . Where should this file be kept in order to access it? I have presently tried keeping it inside the WEB-INF/Classes folder and in the root dir of the application inside glassfish/domains/domain1/
Where should I place this file??
You may consider taking advantage of the FaceContext as mentioned below.
You can create a folder (repors) inside your WEB-INF for example.
String pathToFile=
FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports/MobileOntologyRev1.owl");

Getting jQuery Error on using ezzeelfinder

Hi I am trying to use ezzeelfinder as file manager
I am getting the following error:
TypeError: jQuery(selector).elfinder is not a function
Query(selector).elfinder().elfinder("instance");
I am using the exact code from the Yii extension website. I do not know what is going wrong, I am using windows 7 with Apache (XAMPP)?
Continuing our discussion from previous ElFinder question let me try to explain more.
Can you look at what is inside elfinder.min.js file included from assets directory (you can use Firebug: Net tab > expand request of /assets/abcdef/elfinder.min.js > Response tab)? It wasn't a script (but some HTML with error) when I've reproduced a problem with such error. So if this JavaScript file is not included then there is no elfinder method extending jQuery and the error message you receive is fair.
Seems to me that this one is a permission issue. elfinder.min.js file cannot be published to assets directory for some reasons. Make sure that all permissions to elfinder.min.js file WITHIN extension's directory are granted. After granting the permissions to this file clean up assets directory and try again. At last, check whether the script has been really published to assets directory and has granted permissions there.
I don't know whether it will be helpful for you but I have an archive with demo files that can demonstrate extension's basic usage (made under Ubuntu though): http://ezze.org/yii/ezzeelfinderdemo.zip
Extract the contents of this archive to the root folder of Yii basic application created from command line using yiic script.