简体   繁体   English

在Web应用程序和Visual Studio for ASP.NET MVC上使用图像

[英]Using images on Web Applications and Visual Studio for ASP.NET MVC

I am developing an ASP.NET MVC applications with MS Visual Studio 2008 SP1. 我正在使用MS Visual Studio 2008 SP1开发ASP.NET MVC应用程序。

My project structure is the default one: 我的项目结构是默认的:

Project |-Content |-css |-img |-Models |-Views |-Controllers 项目| -Content | -css | -img | -Models | -Views | -Controllers

The thing is, I am able to access all the content placed under Content directory provided the file is included in the project. 关键是,我能够访问所有内容目录下放置的内容提供的文件中包含该项目。 On the other hand, if I happen to have an image (IE an image uploaded by the user) that's on the right physical directory (Project\\Content\\img) but is not included in the project, I keep getting a 404 error when I access them with a browser. 另一方面,如果我碰巧有一个图像(IE是由用户上传的图像),它位于正确的物理目录(Project \\ Content \\ img)上,但未包含在项目中,我一直遇到404错误使用浏览器访问它们。

I think my URL is correct: 我认为我的网址是正确的:

http://localhost:1260/Content/img/my_image.jpg HTTP://本地主机:1260 /内容/ IMG / my_image.jpg

And I do have a file under Project\\Content\\img\\my_image.jpg. 在Project \\ Content \\ img \\ my_image.jpg下有一个文件。

What can be wrong? 有什么不对? Am I forced to include all the files on the project? 我是否被迫在项目中包含所有文件? I don't think so, because that would mean that I can't have images uploaded and saved by the web users this way. 我不这么认为,因为这意味着我不能以这种方式上传和保存网络用户的图像。

Thanks a lot. 非常感谢。

If you're hosting your project with IIS 7, you must add he content-type in IIS 7(Handler Mapping). 如果您使用IIS 7托管项目,则必须在IIS 7(处理程序映射)中添加内容类型。 But if you're hosting your project with the Asp.net Developer Server, it's not required. 但是,如果您使用Asp.net Developer Server托管您的项目,则不需要。

Using the following code in web.config file 在web.config文件中使用以下代码

<configuration>
   <system.webServer>
     <handlers>
      <add name="css mapping" path="*.css" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
      <add name="js mapping" path="*.js" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
      <add name="gif mapping" path="*.gif" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
      <add name="jpg mapping" path="*.jpg" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />
      <add name="png mapping" path="*.png" verb="*" type="System.Web.StaticFileHandler" resourceType="Unspecified" preCondition="integratedMode" />      
     </handlers>
   </system.webServer>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio Visual Studio MVC asp.NET Google Map - Visual Studio Visual Studio MVC asp.NET Google Map 如何在ASP.NET MVC 4 Web应用程序中使用LINQ更新两个表 - How to Update Two Tables using LINQ in ASP.NET MVC 4 Web Applications 在ASP.NET MVc Web应用程序中如何使用.contains进行搜索和自动完成搜索 - How scalable is using .Contains for searching and auto-complete search in asp.net MVc web applications ASP.NET Web应用程序 - Asp.net web applications 我们如何在 Visual Studio Code 中调试 ASP.NET MVC Web 应用程序? - How can we debug ASP.NET MVC web application in Visual Studio Code? 如何在Visual Studio社区2013中创建ASP.NET MVC 5 Web应用程序? - How to create ASP.NET MVC 5 Web Application in Visual Studio Community 2013? Visual Studio使用旧的dll参考构建ASP.NET MVC Web - Visual Studio building ASP.NET MVC Web with old dll reference 是否可以在 Visual Studio 中连接现有的本地数据库并使用 ASP.NET mvc Core 在 Web 上生成数据? - Is it possible to connect an existing local Database in Visual studio and generate the Data on Web with ASP.NET mvc Core? 如何将ASP.NET MVC 5 Web App部署到带有Visual Studio 2015 Enterprise的Apache(带有Mono)? - How to Deploy ASP.NET MVC 5 Web App to Apache w/ Mono w/ Visual Studio 2015 Enterprise? 使用 ASP.NET MVC web 应用程序 - Using ASP.NET MVC web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM