File not found error in Asp.net 4.0 - asp.net

On Local host,my solution works fine but on server when i deploy ,it gives that file not found error. and the error message is something like this.http://localhost:27375/favicon.ico
I don't have any such file in my application.I tried to create on in the root folder but no luck.any help is highly appreciated

Your favicon.ico file should be in your root directory for the web site.
It looks like your application is still trying to connect to the localhost in order to display the favicon. Are you hard-coding your URL to the favicon with a http://localhost:27275/favico.ico address?
To build on what Internet Engineer said, using ASP.NET, you can use a relative path prefaced with ~ or /. So, you can use ~/favico.ico or /favico.ico in order to reference your icon file.

First check in web server if you can see the file directly in the browser:
http://productionwebsite/favico.ico
If the file is there, now you need to check that the code is using relative paths. Most likely this is coded using absolute paths.

Related

web.config file not there in the root(/) directory

I was trying to run a .cshtml file but it gave an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /index.cshtml
So I searched for the solution and found that I had to edit the web.config file which is in the root directory(here it is My Site), but there is no file like that there there is only an index.cshtml which I had created.
I searched even the IIS and the IIS Express folders in Programs Files\ but there was no file like that?
If you are using WebMatrix, maybe your mistake was the starting point choice.
If you want to create a new Web Pages site you must start from a template in the Template Gallery of WebMatrix. Pay attention that the Empty Site template differs from the Empty Site option outside the Template Gallery because the first holds the files (binaries, packages and the web.config too) that are needed.
As the server error suggests, .cshtml files are not served, the reason for this is because they are server-side files that make up your application, they are just one piece of a much bigger picture.
If you launched your web application in debug mode and the URL in the browser was something like http://localhost:2932/Views/Home/Index.cshtml, just drop the /Views/Home/Index.cshtml part of the URL.

Using Server.MapPath() to generate img src, not working

This seems like a basic question, but I am looking for a proper way of doing this. I am displaying a series of images and their source in view looks like this:
src="#Server.MapPath(Path.Combine("~/App_Data/",photo.ClientId.ToString(),photo.PhotoId.ToString())+photo.FileExt.ToString())"
Which compiles to:
"c:\users\architect\documents\visual studio 2012\Projects\PhotoManagement\PhotoManagement\App_Data\5\62.jpg"
I triple checked that the files do exist at this location. Why does the browser refuse to display this image? Is there a workaround so that the code still works on the server when I upload it.
Thanks.
APP_Data is a restricted folder intended for Datasources such as Database only. ASP.Net will not deliver a file in here - try it by going to the URL for that image directly (I.E www.mysite/App_Data/5/62.jpg ) and you will see the error message HTTP Error 403 - Forbidden.
Put your images in a folder outside of this and you will be fine, such as a folder in the root Called Images
Server.MapPath returns the path of the image on the server. Unless the client happens to have an image in exactly the same path on their computer, this will not work.
Try using Url.Content instead:
src="#Url.Content(Path.Combine("~/App_Data/", photo.ClientId.ToString(), photo.PhotoId.ToString()) + photo.FileExt.ToString())"

Server.MapPath isn't pointing to the actual server path when deployed

I put the server.MapPath code in ASP.NET VB code behind.
On my laptop i compile and build. However when i upload my web application to the actual server. I received error where the link is still referencing the laptop link.
How can i solve this issue?
My code is
Server.MapPath("./scorecardsheet/db.xls")
Actual server link is c:\Inetpub\vhosts\xxx.com\httpdocs\xxx\scorecardsheet\db.xls
but when i run the page on the server it shows the link of my development platform as c:\user\jerry\visual studio 2010\projects\xxx\xxx\scorecardsheet\db.xls
You probably want Server.MapPath("~/scorecardsheet/db.xls") instead, yes? Note the special ASP.NET tilde (~) symbol instead of the current directory symbol (.) This way it will calculate the relative path based on the location of the web site root wherever it is on the system.

ASP.net relative paths not working?

This should be pretty simple but it's not working.
I have a file underneath the root of my project. I want to call it like this.
GetWorkbook("tplBud806_wRevenue.xls")
I publish the project out to the server and try to run it and the server says it can't find it.
Could not find file 'c:\windows\system32\inetsrv\tplBud806_wRevenue.xls'.
That's not the path it should be taking. It should be under E:\IIServer\rootwww\reports\tplBud806_wRevenue.xls.
I thought relative paths were supposed to start from the path that the project was running in. I've also tried.
GetWorkbook("/tplBud806_wRevenue.xls")
GetWorkbook("\tplBud806_wRevenue.xls")
GetWorkbook("~/tplBud806_wRevenue.xls")
GetWorkbook("~\tplBud806_wRevenue.xls")
Is there some setting I'm missing? It's got to be something simple...
GetWorkBook(Server.MapPath("tplBud806_wRevenue.xls"));
GetWorkbook is not an ASP.NET function, and it likely defaults to the folder that the process calling it was started from. The process in this case is an IIS process and probably started in that folder.
Server.MapPath?
Your application is running in an AppDomain loaded by the w3wp.exe located in the directory in your error. Which means that trying to look for any file will start in that directory. You should use Page.MapPath, as mentioned by others. It tells the application to start looking in the folder your aspx is in.
GetWorkBook(Server.MapPath("~/tplBud806_wRevenue.xls")); If the .XLS file is at the root of your project.
You can use also use ~ in conjuction with ResolveURL() to access an URL in your site. So ~ will be replaced by the root URL of your project
Example:
ResolveURL("~\tplBud806_wRevenue.xls")
will be transformed to
http://myproject.url/website/tplBud806_wRevenue.xls
If you need disk access, like in your example, use Server.MapPath
Look at this SO post to learn more about Server.MapPath

What IIS 6.0 setting determines how a path is resolved?

I have a website that is deployed between 3 different environments - Dev, Stage, and Prod. For Stage and Prod, the site can resolve local paths to images with just the base url to the file, such as /SiteImages/banner.png. However, on the Dev server I have to hard code the full URL of the image path for the image to be resolved, such as http://server/folder/SiteImages/banner.png. Is there a setting I can flip to make the Dev server behave in the same manner as the other 2? I am using IIS 6.0 on a Win 2003 server.
There are usually three kinds of URIs that you can code in a website as far as I know.
Absolute: http://yoursite.com/somehing.jpg
This url includes the http:// and is
the full path to a resouce.
Root Relative:
/something/something.jpg
(In ASP.net
server-side only, you would use
'~/something/something.jpg')
This path is relative to the root of
your site.
File relative:
../something/something.jpg
This path
starts at the location of the file
that includes the URI. In this case,
it just back one directory (..) and
then goes back into the something
directory to look for something.jpg
What does the URL to the dev home page look like? Is it something like http://server/mydevsite/? If so, it sounds like you need to set up a virtual host.
Edit Just to clarify the above, say your prod and stage sites can be simply referenced as http://stagesite/ and http://prodsite/, if you use a path such as /images/myimage.jpg it assumes that the images folder are sitting in the root. In those two instances, no problem, images will display correctly. However, let's say your dev server is like the example I listed above. If your images are references as /images/myimage.jpg, instead of the server looking at http://server/mydevsite/images/myimage.jpg, it will instead look at http://server/images/myimage.jpg. If no images folder with the requested image exist in that server's root, you'll get an error.

Resources