CSS and image paths not working - asp.net

Paths defined within master files are not working on a new server. They worked fine on production server and development machine. Here is an example of the file:
/HeadOffice/Styles/HeadOfficeCalendar.css
Unless I put full URL with the virtual name, the paths don't work.
working:
https://connect.server.co.uk/FesQA/HeadOffice/Styles/HeadOfficeCalendar.css
I can also include resolved URL within ASP>NET code tags but I don't want to change all those paths they are probably hundreds of them. so if the head office folder is in the same folder as master file it should just be able to reference like:
/HeadOffice/Styles/HeadOfficeCalendar.css
It seems the references within the master files and aspx files seems to work fine by adding ~ and runat = server. but images references within the CSS files are not working unless I include the full path.
DOESN'T WORK
url(/HeadOffice/Images/tlcorner.png)
DOES WORK
url(connect.server.co.uk/FesQA/HeadOffice/Images/tlcorner.png)

I know I've answered this before, but this has been known issue forever in VS.
Simple way to do this correctly is to drag the CSS file from Solution Explorer window to head section of master page in code view.
For other links on your site, make sure to include the runat="server" attribute and resolve your links like this (with "~" operator):
<img src="~/images/sample.jpg" runat="server" />

Related

how do i solve issues regarding external style sheet link which is not in the same directory of the programming file,but works?

I programmed a page (read index.php) including front end and back end operations,and in between i included a link -<link rel="stylesheet" href="style.css" type="text/css">, but there is no effect on the front end application whether I put this css file in the same directory of index.php or delete it. But when I remove the link from the programming page then the front end page is affected. So, how do I conclude this situation? Please anybody help me. I don't understand how the css file works when it is not in the directory where programming page lies.
Based on the information given it sounds like the file is being included from a cache.
Deleting the file on the server wouldn't affect the page render since there is a locally cached version of the file but deleting the link would prevent the browser from loading the cached version.
Sometimes when working on your localhost you have to put the entire path of the CSS file, not just it's normal location as you do when on a live website. Copy your entire path in the href on the link tag and see if it works.
Normally, if the file is in the same place as your index, you put the href the same way it is written in your example above. If your CSS file is in another folder, you would put ../style.css instead. Writing like that, will move up one folder.

ASP.NET: urls in plain html files can't find app root

A client I'm working with insists on including a plain-jane html file in the ASP.NET app and I can't get the link urls to work properly. Here's an example:
<li><a class="nav_history2" href="/history.html">History</a></li>
It finds the server root (as I expect) but how to modify it to respect the app root? I'm looking for an equivalent to the ~. The client has tried ../ but claims it still finds the root. How is that possible? What SHOULD it look like please?
I don't have the ability to run it on his prod server, so I can't see the problem directly.
----- Edit -----
If I follow the suggestions given in the first two answers it will work if I turn the html page into an aspx, but so far not in the raw html file.
If I remember correctly, you just need to make ASP.NET actively aware of the tag, and the ~ symbol will work. Try:
<a class="nav_history2" runat="server" href="~/history.html">

<img> tag in masterpage does not show logo when called from IIS virtual folder?

It works fine when I dont use virtual folder. My virtual folder is named test which points to an application inside MyDocuments. The path to my App is
localhost\test\app\login.aspx
Note that if I move the application in the root folder wwwroot and make it an application, it works fine. I tried
<img src="logo.jpg" />
<img src="..\logo.jpg" />
<img src="~/logo.jpg" />
<img src="\\test\logo.jpg" />
Can it be fixed or should I leave it? My logo.img is in root folder of the application. I move it to \images\ folder as well still does not work.
There is a similar post here Relative Path in master page for img tag which did not solve my problem because it does not use Virtual Folder path.
Edit: I did used tag also and it did not work too.
<asp:Image ID="imgLogo" runat="server" ImageUrl="~/logo.jpg" />
Thanks in advance
Try adding runat="server" within the your html img contrl and select the src="" from the intellisense property of the visual studio.
or
Use Asp image server control instead of html img control and set the imageurl attribute from intellisense property of the visual studio.
Hope this will help you...
Use the asp:Image, it does all the hard work for you and gets rid of this kind of problem.
The ~/logo.jpg syntax only works in server controls, such as <asp:Image />. The ~ is then a shorthand for the root of your web-application.
If your 'test' directory is an application, then the logo should be there to be found.
To troubleshoot these kind of problems, you need to know the mapping between the physical location of your page ('login.aspx') and the url used to call it. A similar mapping will exist between the physical location of your image and the url you need to get it.
You could try to enter the url for that image directly in the browser. When you have a url that succeeds, you can figure out how to refer to that image from your page.
If it's in the same directory, a plain 'logo.jpg' will work. If elsewhere, you need to add some folderpaths ('images/logo.jpg' if it's in a folder named 'images' next to that page).
I had the same problem and above solutions worked for me.
I know this is old post.
In Masterpage all you have to do is
drag and drop Image
then go its properties and set the url (You can browse it from there)
Now all my pages have the logo with no issue of finding it.

Why does my localhost image url change

I have a bunch of images in my localhost folder (C:\inetpub\wwwroot\Images) which I am trying to access within my ASP.net application. The image src generated in my markup is:
<img id="MainContent_MainImage" src="localhost/Images/FGOStuart_7166.jpg" />`
This fails to load the image and if I look at the source for the page it actually directs to
http://localhost:64395/Pages/localhost/Images/FGOStuart_7166.jpg
so it looks like it is trying to access a path relative to the page (on the Pages folder). The src works if I type it into the browser manually and the image is displayed.
Can anyone explain what's going on here and how to fix it? I'm attempting to move the images out of the database and onto the file system but without much luck so far.
That's because the browser assumes "localhost" is a folder and adds it to the current relative path. Add http to it and it should work fine, or remove localhost altogether and just leave the /Images... part.
Try it like this:
<img id="MainContent_MainImage" src="~/Images/FGOStuart_7166.jpg"
alt="An Image" runat="server" />
This resolves it server-side from the root down. And always use an alt :)
What you really want to be doing is using the magic tilde:
<img id="MainContent_MainImage" runat="server" src="~/Images/FGOStuart_7166.jpg" />
~ signifies the root of the application. Notice I added runat="server", too.

Where do I put my CSS, how do I link to it from the master page?

I have installed SharePoint 2010 on a single machine in farm mode pointing to a db on another server. I would like to start dabbling into branding the site by doing something that I initially thought to be trivially straightforward, link to a custom CSS from a SharePoint 2010 master page.
I have uploaded a custom css (Let's call it custom.css) using SharePoint designer in the Site Assets. What syntax do I need to put to link to it? I have tried the following:
<SharePoint:CssRegistration name="custom.css" After="corev4.css" runat="server"/>
But the server cannot find the CSS file. I receive the following error:
Cannot make a cache safe URL for "1033/styles/custom.css", file not found. Please verify that the file exists under the layouts directory.
I've assumed I need to use SharePoint:CssRegistration - Is my assumption correct?
So what is it exactly that I need to put in the name tag to link to a css uploaded via SharePoint designer?
Am I even on the right track or would you suggest an alternative way of putting this together?
I would use Alternate CSS first. But other options are:
If you put the CSS file in Style Library, you can do this:
<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/custom.css%>" runat="server"/>
Put the CSS on the server as 14\TEMPLATE\LAYOUTS\1033\STYLES\custom\custom.css and then you can do this:
<SharePoint:CssRegistration name="custom/custom.css" runat="server"/>
Putting the file into its own directory is considered best practice so that it does not interfere with updates to out of the box files.

Resources