2012-08-23 3 views
4

개발 컴퓨터에서 내 프로덕션 IIS7.5 서버로 첫 번째 MVC4 프로젝트를 배포했는데 이미지가 서버에 제대로 표시되도록하는 데 문제가 있습니다.MVC4 프로젝트 이미지가 표시되지 않습니다.

IIS7에서 권한 문제 일 수 있습니까?

enter image description here

나는 이것이 내 바탕 화면에 이미지가 올바르게 표시됩니다 실행하지만 서버에 배포 할 때 나는 표준 깨진 링크 이미지를 얻을

<input type="image" src="Content/Images/Product.png" runat="server" /> 

. 이미지가 올바른 경로의 서버에 있음을 확인했습니다.

은 또한 ~ 문자 src="~/Content/Images/Product.png"를 사용하도록 SRC를 변경 시도했지만이 또한 site.css 파일 크롬에서

<head> 
    <meta charset="utf-8" /> 
    <title>@ViewData("Title")</title> 
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> 
    <script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/modernizr-2.0.6-development-only.js")" type="text/javascript"></script> 
</head> 

의 로딩에 영향을하기 시작

여전히 작동하지 않습니다 내가 찾을 수 없다는 오류가 나타납니다 그리고 그 어떤 브라우징에 로딩 아니지만 디스크에 확인했습니다. 이상한 enter image description here

뭔가 일이 일어나고 ...

의 Web.config

<?xml version="1.0"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=152368 
    --> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> 
    </configSections> 
    <appSettings> 
    <add key="webpages:Version" value="1.0.0.0"/> 
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/LogOn" timeout="2880"/> 
    </authentication> 
    <pages controlRenderingCompatibilityVersion="4.0"> 
     <namespaces> 
     <add namespace="System.Web.Helpers"/> 
     <add namespace="System.Web.Mvc"/> 
     <add namespace="System.Web.Mvc.Ajax"/> 
     <add namespace="System.Web.Mvc.Html"/> 
     <add namespace="System.Web.Routing"/> 
     <add namespace="System.Web.WebPages"/> 
     </namespaces> 
    </pages> 
    <profile defaultProvider="DefaultProfileProvider"> 
     <providers> 
     <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/> 
     </providers> 
    </profile> 
    <membership defaultProvider="DefaultMembershipProvider"> 
     <providers> 
     <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/> 
     </providers> 
    </membership> 
    <roleManager defaultProvider="DefaultRoleProvider"> 
     <providers> 
     <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/> 
     </providers> 
    </roleManager> 
    <sessionState mode="InProc" customProvider="DefaultSessionProvider"> 
     <providers> 
     <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/> 
     </providers> 
    </sessionState> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> 
    </entityFramework> 
    <connectionStrings> 
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-QSmartRectification-20120731104636;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-QSmartRectification-20120731104636.mdf"/> 
    </connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="Synchronise" /> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://172.30.66.20/QSmart/Synchronise/" binding="basicHttpBinding" 
     bindingConfiguration="Synchronise" contract="QSmartRectificationProvider.ISyncProvider" 
     name="Synchronise" /> 
    </client> 
    </system.serviceModel> 
</configuration> 
+0

, 그것은 제대로 보이지 않습니다? –

+1

'src = "~/Content ..."'시도하십시오 - 절대 경로,'~ /'로 시작하는 주석. – Rolice

+0

아니요, 물결표를 사용하지 않으면 가상 경로 별칭이없는 http : //rociis21/Content/Images/Product.png가 표시됩니다. tilda를 사용하면 http : //rociis21/~/Content/Images/Product.png –

답변

7

이것은 절대 경로에 문제가있을 수 있습니다. 페이지가 ActionResult 뷰이고 기본 라우팅 규칙이 적용되면 대신 "../../content/product.png"를 시도 할 수 있습니다. 또는 helper @ Url.Content ("~/content/product.png")를 사용할 수도 있습니다. 브라우저로 항상 절대 경로를 확인할 수 있습니다.

라우팅 규칙을 확인하고 콘텐츠 폴더를 컨트롤러에 매핑하는지 확인하십시오.

+0

두 개 모두 시도했지만 URL.Content가 내 컴퓨터에서 다시 작동하지만 서버에서는 작동하지 않습니다. –

+0

안녕 Phil, 브라우저에 절대 URL을 수동으로 입력하여 이미지를 렌더링 할 수 있습니까? 나는. 'http : // yoursever/folder/yourApp/content/product.png' – Ben

0

이 이미지를 호출? 당신은 "보기"폴더 중 하나에있는 경우 당신은 src="../../Content/Images/Product.png"

메모를 시도해야합니다 : 각 .. 하나 개의 폴더까지를 의미한다.

+0

보기에서 전체 상대 경로를 시도했습니다 (src = "../../ Content/Images/Product.png"). 다시 내 컴퓨터에서 작동하지만 서버에 배포하는 경우에는 그렇지 않습니다. –

0

"/"앞에 접두어를 붙이시겠습니까?

<input type="image" src="/Content/Images/Product.png" runat="server" /> 

한 번 더 생각하면 라우팅에서 사실로 RouteExistingFiles 속성을 설정했을 수 있습니다 및 때문에 CSS와 이미지가 로딩되지 않는 것입니다. 당신은 이미지 링크에서 볼 때

+0

기쁨도없이 노력했습니다. VS2012 RC 또는 MVC 4의 버그인지 궁금한가요? –

+0

라우팅 코드를 게시 할 수 있습니까? RouteExistingFiles를 true로 설정 했습니까? – VJAI

0

당신이 yourPhoto server.MapPath("Images")+yourPhoto 또는 Mappath(".")+\\Images\\+로에 액세스 할 수

관련 문제