I am using RCL with Blazor Wasm and net 6-rc1
My images in the RCL (CommonComponents) project are in the wwwroot / lib / bootstrap-icons / icons folder.
In Net 5, all images are received from the Controller and web api with the following code:
var rootPath = _webHostEnverioment.WebRootFileProvider.GetDirectoryContents ("/ _ Content / CommonComponents"). FirstOrDefault (x => x.Name == "lib"). Physical path;
But when projects are updated from .net5 to .net6, PhysicalPath is empty
In version 6, webHostEnvironment. WebRootPath also returns null
Has access to folders and their contents changed in .NET 6?
I had same issue. In .net 5.0 WebRootFileProvider is simple PhysicalFileProvider, but in .net 6.0 CompositeFileProvider is used with 2 providers under the hood: ManifestStaticWebAssetFileProvider and PhysicalFileProvider
ManifestStaticWebAssetFileProvider returns null for PhysicalPath property for directories. I could not google any info about ManifestStaticWebAssetFileProvider and why we need it. To revert old behavior you can do in startup class:
_webHostEnverioment.WebRootFileProvider = new PhysicalFileProvider(_webHostEnverioment.WebRootPath);
Related
I am running ASP.NET Core on MacOS and deploying to Heroku, and I'm getting an UnauthorizedAccessException trying to load json files sitting in my web app folder.
My web app is in /Users/xyz/Repos/ProjectName/web/ and the json files are in a subfolder /Users/xyz/Repos/ProjectName/web/data.
The exception I'm getting is:
Access to the path '/Users/xyz/Repos/ProjectName/web' is denied
The code I'm using is:
string path = Path.Combine(_env.ContentRootPath, "data/my_data.json");
JsonSerializerSettings settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore
};
StreamReader sr = new StreamReader(path);
var json = sr.ReadToEnd();
JsonConvert.PopulateObject(json, this);
In the old days I would just give the IIS user access to this folder, but we're in .NET Core land now and anyway I need to deploy this to Heroku and getting it to work.
Any suggestions for how to get this working would be most sincerely appreciated!
I'm porting an ASP.NET MVC application to .NET Core.
One of the apps dependencies is a .NET Framework dll that uses Entity Framework 6.
I added the settings from the old ASP.NET MVC app and referenced System.Configuration.ConfigurationManager to use the old settings file format in the new app.
When I run the app I get an error:
No connection string named="myEntity" could be found in the application config file.
How do I add the connection string to my new .NET Core app?
Add you connection string to your appsettings.json like this:
"Data": {
"DB": "metadata=res://*/AppDB.csdl|res://*/AppDB.ssdl|res://*/AppDB.msl;provider=System.Data.SqlClient;provider connection string='Your Connection String Goes Here'",
},
Read your connection string like this:
IConfiguration["Data:DB"]
For more information on how to do this: ASP.NET Core Configuration
Then pass the connection string in your DBContext's constructor.
This is how I do it in one of my applications with the same scenario.
Your will need to modify your T4 Template (NameOfModel.Context.tt) in the project that has the EDMX file:
Add this line to the constructor:
: base(ConfigHelper.GetConnectionString("<#=container.Name#>"))
Where ConfigHelper.GetConnectionString is a static class with a method to read the configuration from the appsettings.json like mentioned before.
I have an application in ASP.NET Framework 4.6.1 that works fine when running in my local environnent using Visual Studio 2017 (version 15.7.27703.2035).
On server side, the same application is displaying an HTTP ERROR 404.
Screenshot on local environment
Screenshot on server environment
To publish the ASP.NET application, I am using the publish tool of Visual Studio and deploy everything on an App Service of Azure.
Visual studio publish tool and project architecture
I tried to use FTP deployment instead of Web Deploy with no success. I also tried manualy with FileZilla with no success.
Is it possible that some sort of action is needed when publishing a project with custom libraries?
EDIT
What I know:
dlls on server side I actualy have access to the wwwroot folder on server side: this mean I can access js, css, images, etc. But it seems that controllers, views and others folders don't exist on the server..
Libraries issus? The problem appeared when I subdivided my project with the customs libraries CrmDatabaseManager, SysaidDatabaseManager and UserInterfaceLibrary.
wwwroot inside wwwroot on server side A wwwroot folder include anoter wwwroot folder on the server; the first wwwroot folder contains all dlls, and inside it, there is another wwwroot folder containing css, js, images and etc, but no sign of controllers or views.
How I created the project I created the project GPRH
this way using ASP.NET Core 2.0 based on .NET Framework
It turns out that split the project with libraries did broke path references.
I was hard coding the path and there were no problems with that into the main project. When I splited the project with libraries, it caused an error 404.
To access a file in a libary, you need to do this manipulation first:
Right clic on the file > Properties
On Build action, choose Always
copy the file
Then specifie the path this way on the library:
var buildDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = buildDir + #"\fileName.json";
using (StreamReader r = new StreamReader(filePath))
{
// code here
}
i have problem in my webapp named "TezBuy" on release mode.
when i run the project , mappath is : D:\My Applications\TezBuy\EShop
but when publishing on localhost , the mappath is :C:\inetpub\wwwroot
how can i solve it?
pls help me
I've got a big problem with create a folder in a WCF application running under Asp.net
Do following steps !
Create Asp.net MVC project -> Done
Create a WCF service inside asp.net MVC project ->Done
Inside WCF, create a method (i just want to create a folder inside this method) named CreateFolder() ->Done - it's works
This is code inside method created :
var path = HttpContext.Current.Server.MapPath("~/UserData");
Directory.CreateDirectory(path);
Well, it's doesn't work !
Now, try again with another code !
var path = HostingEnvironment.MapPath("~/YourDirectory");
Directory.CreateDirectory(path);
Again, it' doesn't work too.
PS: it's only works on Local machine PC.
When i published asp.net Website and upload to my hosting, everything good except above method(create folder)
Any idea ?
PPS: I just want to create Folder for user registered !
Test it with a direct path address, like "d:/UserData" instead of "~/UserData".