I am a newbie in asp.net. I m trying to add a logo in my _layout.cshtml file but it's not getting into view. It's showing a broken image. The image is in Assets folder. Don't know what I am doing wrong. Any help would be appreciated.
Here's the screenshot of my code and structure.
For static files in asp.net core, you need to place them in wwwroot folder in your project by default.
Follow steps below:
Move Assets folder to wwwroot
Change the html code like:
<img src="~/Assets/logo.png" />
Related
I am getting an error, when trying to include a css file in the bundle, it says that Asp.net MVC Bundle - Only application relative URLs (~/url) are allowed.
Here is the code:
bundles.Add(new StyleBundle("~/bundles/lib/anim_css").Include(
"~Vendor/lib/animate/animate.min.css", new CssRewriteUrlTransform()));
Where the Vendor folder is the source folder of that css. That folder is included in the project, being like that ...ProjectFolderName/Vendor
This did not help
~Vendor/lib/animate/animate.min.css is not a legal relative URL. It needs to be ~/Vendor/lib/animate/animate.min.css
I have subfolders of JS and CSS in my wwwroot folder of asp.net core razor page application. Application works fine in local environment, but while deployment of the project on IIS, the wwwroot folder does not contain any subfolders or files in it.
Even if I manually upload the folders and files to wwwroot folder, it doesn't work and it does not load the JS and CSS files in the browser.
Note that I do not have "Environment" tags in my application.
Try to edit the .csproj file of your asp.net core project:
Remove all the ItemGroup tags and their contents then add this
<ItemGroup>
<None Include="wwwroot\*" />
</ItemGroup>
You could refer this link for more detail:
Visual Studio publish profiles for ASP.NET Core app deployment
There are two ways of setting the js/css path
Absolute Path
Relative Path
Absolute Path is, you have to give proper path in web server .
http://<website name>/css/site.css
Relative Path is, you can give file page relative to current page.
let say your page is from http://<website name>/index.html
relative path will be ./css/site.css
Better you try to access js or css file from browser. may be these folders do not have right permission to access.
if you open Dev Tool, you can see the error in Network tab or console. Base on HTTP code, you can decide what has happened
In my scenario I was adding MVC to my .Net 5 API
The solution was to add
app.UseStaticFiles();
to the Startup.cs
I create new asp.net mvc project in visual studio 2015.The project has a wwwroot file.What is this?
Quoting the official website:
The wwwroot folder is new in ASP.NET 5.0. All of the static files in
your project go into this folder. These are assets that the app will
serve directly to clients, including HTML files, CSS files, image
files, and JavaScript files. The wwwroot folder is the root of your
web site. That is, http://some.hostname/ points to wwwroot, all URLs for
static content are relative to the wwwroot folder.
Code files should be placed outside of wwwroot. That includes all of your C# files and Razor files. > Having a wwwroot folder keeps a clean separation between code files and static files.
Source
It's worth mentioning that the term wwwroot itself is certainly not new and it's actually a convention used across many platforms (including J2EE applications and IIS itself with its c:\inetpub\wwwroot directory).
Similar conventions in the Unix/Linux world are htdocs, public_html and www.
The wwwroot folder is new in ASP.NET 5 to store all of the static files in your project. Any files including HTML files, CSS files, image files, and JavaScript files which are sent to the user's browser should be stored inside this folder.
Code files should be placed outside of wwwroot, including C# files and Razor views. Having a wwwroot folder keeps a clean separation between code files and static files. It brings clarity to the items that will be sent to the server and the items that should remain on the dev machine. If you look at the screenshot, wwwroot folder has css and lib sub folders. Css folder is a place to keep your custom css files, while lib folder is used by Bower package manager. The lib folder contains the packages downloaded by Bower and can contain css, js and images.
The screenshot shows that lib folder has a bootstrap package folder. If you expand it, you will find css, js, as well all other assets related to the bootstrap package.
In MVC4, we used the content folder to keep style sheets as well as scripts folder for referenced scripts. These folders are gone now, so it's important to understand that there is no single folder for style sheets or scripts. They could be in any of the folders within wwwroot.
It's interesting to note that if you wish to reference the css, js, or img files in your razor views, using the ~ keyword ensures direct path to the wwwroot folder. So suppose you wanted to reference site.css in your view, you can access it using the <link rel="stylesheet" href="~/css/site.css" /> syntax.
You can see that the ~ keyword points to the wwwroot folder.
I have written some code for saving an image to a folder in asp.net. My problem is that the image in the folder is white and is not the same as images added manually to the folder.
I used a simple asp.net fileupload control to save the file to the correct path. But the images dont display on the page and this is how the file icons look in visual studio.
Anybody know why this is?
Try Right-clicking the images and select "include in project"
edit
If you want to do that programmatically you need to modify the project file programmatically; that's all there is to it. It's an XML file with nothing special about it. Note, however, that you have this under source control and you'll probably need to do more than just modifying the project file (ie adding the file to source control too)
Yes, it is. Because it is not included as part of the project files.
Try this:
There isn't anything else that is wrong. Only the files are not tracked by VS, so they won't be published. Your files are still completely accessible from your code.
In my opinion, files like say images added to your web app shouldn't be part of the project.
You need to include them in the project by right clicking them and click Include In Project.
Furthermore, if you want these files to included in the build you need to go to Properties of each file and set Build Action as Content.
I've been working in a multilanguage site build with asp.net and visual c#.
I'm using Local_resources to get my aspx files in Spanish and english.
If a use my aspx in the root of the website the Local_resources folder find the aproppiate resx for my aspx (because both have the same name). But if i put all my aspx into a folder created in the root directory, everything stop working:
as you can see i have a folder named "Inventario" and inside that folder i have Productos.aspx.
In App_LocalResources i have two files, one for spanish and one for english.
If i put Productos.aspx in the root directory they work fine, but i need them like in the image and like that is not working.
What should i do to the resx files to point to Inventario/Productos.aspx ?
Thank you very much.
You have to create a new App_LocalResources folder under Inventario, then copy Productos.aspx.*.resx from <root>\App_LocalResources to Inventario\App_LocalResources, then rebuild your solution.