replace favicon in mvc4 - asp.net-mvc-4

I have provided <link rel="shortcut icon" href="~/Images/logo.gif" /> in my layout but i wish to replace the favicon on all the pages, even where layout is not used.
I replaced the favicon file with my favicon (present in the root folder) still it loads the default favicon on pages without layout.
What more needs to be changed in order to get my favicon.
a similar but slightly different question has already been asked but isnt answered by anyone.link

It's better to convert your .gif to .ico, you can do this online
It's a convention to rename the icon to 'favicon.ico'
You can find more information on Wikipedia - look at the section 'How to use'
Your html should look like:
<link rel="shortcut icon" type="image/ico" href="~/Images/favicon.ico">
Check Mark Gravell's solution here

Related

ASP.NET page is not loading CSS styles on my local iis web server

I have a local ASP.NET web site written in VB.NET runing on W7.
The default web page contains a simple style sheet which is loaded as follows
<link rel="stylesheet" href="dchs.css" type="text/css" media="screen" runat="server"></link>
The page is displayed without the above styling. The style sheet does exist as I can display it via the web browers as
file:///c:/inetpub/wwwroot/c1/dchs.css
but I cannot display it via the brower using
http://localhost/c1/dchs.css
This leads me to believe that IIS has some form of access problem to the C1 directory. It a similar way I can display a jpeg image via file://c1 bit not via localhost which gives an error message
The image "http://localhost/c1/menu.jpeg" cannot be displayed, because it contains errors.
How you attached the .css file to your html project? where is it located?
Options:
1. Drag and drop your .css file to your html page.(Inside)
like this:
<link rel="Shortcut Icon" href="images/fil.ico" />
Make sure all folders and files are include when project deployed And a correct calling of id or class in your css of course.

Resolving js and css urls affected by app.Map in ASP.NET 5

I am implementing multi-tenancy based on the first folder segment of the request url.
As such I'm configuring each tenant separately by branching with IApplicationBuilder like this:
PathString path = new PathString("/somefolder");
app.Map(path,
branchApp =>
{
// code goes here to configure the branch
}
as a result of this if my view has a link with url /Home/About for example, it automatically is adjusted to be relative to the folder I branched on when I visit /somefolder, ie the links change to /somefolder/Home/About, somefolder/Home/Contact etc
This was kind of unexpected to me but actually helpful.
But also if my view has
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/lib/jquery/dist/jquery.js"></script>
those now resolve to /somefolder/css/site.css and /somefolder/js/lib/jquery/dist/jquery.js
which is not what I want.
Is there some way I can change this behavior for js and css but keep it for navigation links?
No, you can't. At least, not easily: when using app.Map, it automatically sets HttpContext.Request.PathBase with the path parameter you specified, which causes the exact behavior you're seeing (it's basically a "virtual directory" equivalent).
The best option is to stop using virtual path links (~/) and replace them by standard root-relative links (/), that are not processed by Razor and MVC.
<link rel="stylesheet" href="/css/site.css" />
<script src="/js/lib/jquery/dist/jquery.js"></script>

MVC 4 razor actionlink address route adds pound char in between

the reason of this question is because I am having troubles with a route address in MVC 4 application, what is happening here is that I have an action link in this way in a view:
<li>#Html.ActionLink("Description", "Action", "Controller")</li>
And when I run the app in the HTML in the web browser appear the link generated correct
<li>description</li>
but when I click on the link in the web address bar the destination route appears as follows:
http://localhost:port/#/Controller
Is inserting a "#" char in between, is doing this for all of the links in my different views, it do the same when I deploy the App in a web server too no only in my local and this makes that the destination page don't appear correct, I don't know the reason of this, I have been searching but without success, hope you can help me, thanks in advance.
I found the reason for that behavior, it was because I have the script load for jquery mobile on the head section in the _Layout_cshtml file like this
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<meta name="viewport" content="width=device-width" />
#Scripts.Render("~/bundles/jquery")
#Styles.Render("~/Content/mobilecss", "~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/jquerymobile")
</head>
What I do was change the location of jquerymobile script to the end of the _Layout.cshtml
#Scripts.Render("~/bundles/jquerymobile")
#RenderSection("scripts", required: false)
</body>
With this change the web route was created correctly, I hope this helps to somebody.

How can I get site's favicon using Selenium

I need to get web site's favicon.
How can I do that?
You won't be able to get the favicon with Selenium you would have to use another program to grab it. The only way you would be able to get it is if your website rendered the favicon.ico as a link such as
<link rel="shortcut icon"
href="http://example.com/myicon.ico" />
However typically websites just store the favicon.ico in the root directory and on page request the browser retrieves it and drops it in the address bar or tab or wherever favicons are used. If this is how your favicon is rendered then there will be no code or anything to search for with Selenium.
Also the above code while it does work has some buggy support for IE7.
You don't need Selenium.
Just request the site's home page and use an HTML parser to find a <link rel="shortcut icon" href="..."> tag.
If you don't find any such tag, try /favicon.ico.
Here is a bit crazy but working solution:
get the favicon image opened in a web page (and hence reachable with selenium) with the help of "http://www.google.com/s2/favicons". There are other services which provide a similar functionality, see:
Get website's favicon with JS
use cssneedle package to compare the resulting favicon with a pre-saved one
Needle is a tool for testing your CSS with Selenium and nose.
It checks that CSS renders correctly by taking screenshots of portions
of a website and comparing them against known good screenshots. It
also provides tools for testing calculated CSS values and the position
of HTML elements.
In other words, we are going to compare favicon images.
Example implementation (python):
from needle.cases import NeedleTestCase
class FavIconTestCase(NeedleTestCase):
def test_so(self):
self.driver.get('http://www.google.com/s2/favicons?domain=www.stackoverflow.com')
self.assertScreenshot('img', 'so-favicon')

How to display a favicon for web app using Tomcat? [duplicate]

This question already has answers here:
How to add a browser tab icon (favicon) for a website?
(13 answers)
Closed 6 years ago.
Does anyone know how to implement a favicon icon for a particular application using Tomcat? This icon file would not be for all webpapps, just this one on the server in question.
Just add the following code in the <head> to your index.html in you webapp/projectName/
<link rel="shortcut icon"
href="http://example.com/myicon.ico" />
I like to add that the original tag type for the link was "shortcut icon", but that didn't
conform to the standard so it was sort of switched to "icon".
So I recomend add both to your head block:
<link rel="icon" href="http://www.example.com/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="http://www.example.com/favicon.ico" type="image/x-icon">
Also some browsers don't support sizes other than 16px X 16px.
Delete or rename tomcat/webapps/ROOT/favicon.ico and Tomcat will look for a favicon.ico in the root of each web app that it serves. You don't need to put a into the head section of each page.
<link rel="shortcut icon" href="http://example.com/myicon.ico" />
add that within the <head> of your page - where the .ico file is an icon - there are several websites (use google) that generate .ico files from pictures (gif / jpeg etc)