繁体   English   中英

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

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

我正在使用MS Visual Studio 2008 SP1开发ASP.NET MVC应用程序。

我的项目结构是默认的:

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

关键是,我能够访问所有内容目录下放置的内容提供的文件中包含该项目。 另一方面,如果我碰巧有一个图像(IE是由用户上传的图像),它位于正确的物理目录(Project \\ Content \\ img)上,但未包含在项目中,我一直遇到404错误使用浏览器访问它们。

我认为我的网址是正确的:

HTTP://本地主机:1260 /内容/ IMG / my_image.jpg

在Project \\ Content \\ img \\ my_image.jpg下有一个文件。

有什么不对? 我是否被迫在项目中包含所有文件? 我不这么认为,因为这意味着我不能以这种方式上传和保存网络用户的图像。

非常感谢。

如果您使用IIS 7托管项目,则必须在IIS 7(处理程序映射)中添加内容类型。 但是,如果您使用Asp.net Developer Server托管您的项目,则不需要。

在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM