I have asp.net app that I am trying to upload to azure host.
first I have try to link in the traditional way with Css folder and link to it
<link href="http://mysite.azurewebsites.net/css/style.css"
rel="stylesheet" type="text/css" />
NOT WORKING
then i create blob and reference to it :
<link href="http://mysite.blob.core.windows.net/scripts/style.css"
rel="stylesheet" type="text/css" />
NOT WORKING
now I dont get error but nothing happend to the styling (after empty my cache and restart the site)
I am not using master pages in my site just normal asp.net page.
i saw in some place that they are doing it with master page but there is other way to do it without master page.
Thanks.
Related
I am trying to do some website by using Bootstrap and Spring Boot.
When I put web location of bootstrap.min.css in href, it is working perfectly.
Code:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
But when I download the same library and put it in a folder, Bootstrap is not recognized at my website.
Code:
<link rel="stylesheet" href="/static/bootstrap-4.5.2-dist/css/bootstrap.min.css">
Can someone explain me how to fix this problem?
I manage to figure this out. Despite the fact that location of file is in static, Spring boot recognizes automatically that it is in static, so it is enough to write href="/bootstrap-4.5.2-dist/css/bootstrap.min.css".
I am building a site and had all of my CSS, HTML working wonderfully. I wanted to add in some PHP functionality so I have created a local development environment on my mac with Apache. I then moved all of my site folders to my new Sites folder that can be accessed by localhost. When loading my website and now none of my CSS styles are loading. I am using Twitter Bootstrap locally. This is what my css links look like in my html:
link rel="stylesheet" type="text/css" href="http://localhost/~tromph/YoointooSite/bootstrap.min.css">
link rel="stylesheet" type="text/css" href="http://localhost/~tromph/YoointooSite/main.css">
I've tried just about every other path that I can think of and nothing else seems to work.
I changed my folder structure and the file path to:
<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.2-dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.2-dist/css/main.css" />
This fixed my problem of not having the CSS render. Now the images linked in the CSS are not showing. Dev tools is telling me that I am getting an error 403 (forbidden) on each of my images. What should I do to change this permission?
I spent some time updating permissions. Everything is working now. Thanks for your help!
I would recommend referencing the CSS files relatively. So if you have the following folder structure.
myProj
- css
- bootstrap
- bootstrap.min.css
- index.html (or php)
Then you would reference the bootstrap file like so
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.min.css" />
Guessing at your folder structure from your example I would then assume that all you need is
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="main.css" />
If however your css files are not in your project, but instead are served externally, then you would need to reference them from wherever you are serving them. For example if serving them to port 8080, then you would need to reference them using that address instead.
<link rel="stylesheet" type="text/css" href="http://localhost:8080/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="http://localhost:8080/main.css" />
Again, the above is only if you are serving them externally from the site that you are attempting to use them from. If they are inside of the project you are working on, then reference them relatively from the file attempting to use them.
The first thing I would look at is whether or not it's a path issue with your styleheets. Use web inspector or dev tools in your browser and look for a 404 error in your CSS files. If there are any, dev tools will show the path it's looking for and you can adjust the path to your style sheets accordingly.
Good luck!
Thought I'd throw my input into the works.
I named one of my CSS files style.css than later went and deleted it and created a new style.css and my wamp server kept referencing the first style.css file I made.
So I renamed the second CSS file to main_style.css and everything worked perfectly.
Use Developer tools in google chrome or other browser and in the sources tab look for errors. Two common errors are your css files not being found (see relative path answer above) or maybe your file permissions don't allow the Apache server to access the CSS files.
I once faced the issue of CSS not being applied when I was working with PHP.
I fixed this issue by doing Empty Cache and Hard Reload (chrome).
To do that:
Open DevTools
Right-click on reload button(top-left)
Click on Empty Cache and Hard Reload
After doing this, all my CSS styles were applied.
I also faced same problem but later found a solution to it. Just Press 'Ctrl+F5' when the css file doesn't open on the browser window.
The problem is that it fails to find any css files and thus the pages render horribly.
In the head section of my master page, I have the following line:
<webopt:bundlereference runat="server" path="~/Content/css" />
When I debug from the IDE and look at PageSource, the above translates to:
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/bootstrap-override.css" rel="stylesheet"/>
<link href="/Content/Site.css" rel="stylesheet"/>
When I point IIS to the project and run using localhost, I get no css applied and the PageSource translates to:
<link href="/QM/Content/bootstrap.css" rel="stylesheet"/>
<link href="/QM/Content/bootstrap-override.css" rel="stylesheet"/>
<link href="/QM/Content/Site.css" rel="stylesheet"/>
"QM" is the Alias I chose when I created the Application in IIS.
My question: Where is the "/QM" prefix coming from and how do I suppress it?
I'm sure I'm just missing something in my IIS setup or perhaps web.config, but I have been unable to find any help from previous questions or the web.
As is often the case, I was reading the symptoms wrong, misinterpreting what was important and not getting any help. Here's what I found:
First, I found that I could get the /QM prefix when running from the IDE as well by adding it in the Project URL on the Properties window of the Project. So that wasn't the problem at all.
What was wrong was that the IIS installation (Turn Windows features on or off) did not have Static Content installed so that even though the Handler Mappings had a handler for StaticFile (already there) it wasn't able to load because that part of IIS wasn't installed. Once it was, my page loaded as expected.
I've just hosted something on Heroku, and whenever I opened the app it worked just fine with the css being linked as such:
<link rel="stylesheet" href="/css/style.css"/>
The problem came when I added my custom domain, the css no longer worked. When I view source and click on the href, it get a response "Not Found". Nothing has changed, my css folder is still in my public folder in my apps directory.
Have you tried different paths for the href, like
href="../css/style.css"
or
href="css/style.css"
When start debug mode of my asp.net website, it renders in my browser with the url
http://localhost:111/mywebsite/Default.aspx
The css file is referenced like this in the html
<link href="~/css/style.css" runat="server" rel="stylesheet" type="text/css" />
So naturally the site breaks because it looks for the CSS file in localhost:111/css/ instead of localhost:111/mywebsite/css/.
When I launch the website, it will actually be served from the url:
http://mywebsite.com
So is there a way to reference my stylesheet properly in both my dev and production area with a simple prefix like <?=$site_url ?> or something?
Additional info
In my solution explorer, I see that my project is marked with the path C:\...\mywebsite. Is that why the ~ assumes my project is always in a subdirectory? How do I tell Visual Studios that this project should always be served as something like http://localhost:111/Default.aspx?
This is what I see in the page source of both my localhost and production server:
<link href="~/css/style.css" rel="stylesheet" type="text/css"></link>. The css is active on production, but not my localhost.
I went to the solution explorer, then selected the item in the tree labelled C:\...\mywebsite, then I went to the Properties window at bottom right of VS, and changed the Virtual path to /. Now my dev website's root is the same as my prod website's root.
This will do the trick.
<link href="<%=ResolveUrl("~/css/style.css")%>" runat="server" rel="stylesheet" type="text/css" />
You already have, ~ resolves to the root of the website when the page is rendered.
Further reading: http://weblogs.asp.net/fmarguerie/archive/2004/05/05/avoiding-problems-with-relative-and-absolute-urls-in-asp-net.aspx (which works in chrome, FF and IE).
~ resolves on the server (which is why you need runat="server").
This code is run to generate the response from a HTTP request that has come to your dev server which is hosting the site from the location of the project on your disk.
~ doesn't assume that the site is in a subdirectory, the dev server will know the root of the website.
In production the site is being hosted by IIS from another location on the disk of the server machine.
Change it to:
<link href="/css/style.css"" rel="stylesheet" type="text/css" />
Remove runat="server" (if you don't need it).
Instead of href="~/css/style.css" use: href="/css/style.css"
href="/css/style.css" means that there is a folder named css in root of your website and a file named style.css inside it.
UPDATE:
As pointed out by comments, this solution only works if your app is running in root.