Unable to view images in mvc3 application hosted in iis 7 - asp.net-mvc-3

I have hosted my asp .net mvc3 application in iis server 7. I had deployed my application under a virtual directory and url to my application is like www.abc.com/virtualdirname . Application works fine and Im able to navigate through pages. However , Im unable to view any images used in my application. I have stored my images in a folder public/images .
cshtml code for one of the image is as follows
img id="start" src="../../Public/images/start_button_start.png"
Im getting error message in place of images and path of image is www.abc.com/public/images instead of www.abc.com/virtualdirname/public/images .
In the app settings of my config file, I had defined virtual dir.
add key="virtualdir" value="/virtualdirname " /
Can anyone tell me why this problem happens and how can I get out of this?

Never hardcode urls in an ASP.NET MVC application. Always use url helpers:
<img src="#Url.Content("~/Public/images/start_button_start.png")" alt=""/>
Url helpers will take virtual directory into account.

Related

Index.html file generated by apidoc.js shows a 404 error after deploying asp.net web api app to server

I used apidocjs to setup the documentation of my asp.net web api app. Everything works fine on my machine when I run my web api in visual studio but not on the server I deployed the app to.
I get a 404 error when I navigate to the index.html generated by apidocjs.
I think it's an issue with IIS.
I need suggestions on how to resolve this?
Ok. Found the problem kind of silly.
I did not include the ~ symbol as part of the path in my anchor tag.
Before I had
I added ~
<li>Docs</li>
<li>Docs</li>
and problem solved!!!
Update.
What I did earlier solved the problem on the deployment i did to my local IIS but not on my remote server.
I had move my static html file into the Content folder of my web-api, edited the link to look like this and the problem was resolved.
Docs
Got this from here. Ordinary html links in mvc razor

How to remove directory name from url with global.asax code

I am using MVC routing in asp.net Web forms and I want to remove the folder/directory name appended in the URL. Locally this works fine but I have the following address now appearing on Godaddy shared hosting.
www.mywebsite.com/my-folder/contact
but I want like this
www.mywebsite.com/contact
I have tried web.config techniques but no success that's why I am asking is there any way to redirect this using Global.asax.

Deploying MVC3 Areas (Admin) Separately without modifying the client content implementation

I have web application let us say "client" where contents are controlled by CMS (using MVC3 areas). Both applications are in the same project and the same solution. We just added area for CMS. The CMS or admin area has upload image functionality then the client displays the contents uploaded by admin. We don't have issue if admin and client is hosted on the same IIS directory however our business needs that both admin and client should be deployed on different directory this will become.
CMS: http://cms.com/admin
Client: http://client.com/
All content uploads take place at cms.com and contents will be displayed at client.com
My main issue is that the project was not designed to get images from other web directory. For example currently all images get the path from client.com
<img src="http://client.com/Content/Uploads/img1.jpg"/>
<img src="http://client.com/Content/Uploads/img2.jpg"/>
<img src="http://client.com/Content/Uploads/img3.jpg"/>
Now my question is, is there easiest way a URL helper or anything I can implement without going through modifying all images to reference http://cms.com/Content/Uploads source? Please help.

can't get zend public subfolders using virtualhost

I create a Zend project. My images are in folder public/icons and they available when I run project using url http://localhost/zendproject/public/icons/image.png but when I use virtualhost http://zend.gameblog I can't get this image by url http://zendgameblog/icons/image.png.
Browser says "403 Forbidden" and I can't understand why. I also have public/captcha folder and any image from this location always available by url http://zend.gameblog/captcha/image.png.
I use: win7 x86, WAMP, zend framework 1.12, Zend Studio 9.0.4. Some of resources and folders I created manually not via Zend Studio.
Please help me and tell whether I will have such problems when I'll run my project at real server?
For all css, js and img on web site use baseUrl helper:
$this->baseUrl('/icons/image.png');
//or
$this->baseUrl('/css/css_file.css');
and for all links on web site use URL View Helper: $this->url(...)

Webform in MVC app does not show in IIS7.5

I have a webform (using the ReportViewer) that is in an MVC application. It is outside the Views folder in a root level folder called Reports. The webform page works correctly when using VS2010 and the web server (Development Server, WebDev.WebServer, Cassini). When using IIS7.5 with an integrated Application Pool (also tried Classic and set the ISAPI restrictions to allow), it does not work. I have the modules..handlers item (Reserved-ReportViewerWebControl-axd) in web.config.
I am getting this page result: "The resource cannot be found." / Description: HTTP 404. The resource you are looking for ...
I hope someone has a fix for this.
Thanks in advance.
Try putting the file(s) under the content folder. That should remove any route problems.

Resources