2017-11-22 14 views
0

ASP NET 코어 2 및 각도로 각도 프로젝트를 구축했으며 지난 2 시간 동안 OWIN에서 호스팅하지 않으려 고했습니다. 저는 Visual Studio에서 직접 표현하는 IIS에서 실행할 때 제대로 작동하는 게시 할 파일을 생성하기 위해 VS 게시를 사용했습니다. 자체 호스트 asp 코어 - 콘솔 응용 프로그램으로 OWIN을 사용하는 앵귤러 2 사이트

가 게시 폴더의 파일 구조입니다 : MainDirectory wwwroot에 DIST 파비콘

내가 설정 .NET (비주얼 스튜디오)에 게시 프로젝트를하고 내 startup.cs 클래스에서 다음을 가지고 있지만 서비스를 시작한 후 url을 탐색 할 때 페이지에 아무 것도 없습니다. 아래 코드를 사용했습니다.

const string rootFolder = "C:\\src\\StartupService\\maindirectory"; 
      var fileSystem = new PhysicalFileSystem(rootFolder); 
      var options = new FileServerOptions 
      { 
       EnableDefaultFiles = true, 
       FileSystem = fileSystem 
      }; 

      app.UseFileServer(options); 

은 내가 C에서 # app.UseWelcome() 페이지로 OWIN 자기 호스트 서버를 테스트하고 괜찮다고하지만 늘 내 각 사이트를 역할을 언급하고 싶다. 그냥 내가 게시 된 폴더에 아무 html 파일을 볼 수 없다는 dlls, json 파일 및 web.config, 그래서 그게 문제인지 모르겠다.

이 코드도 시도했지만 작동하지 않았습니다.

var physicalFileSystem = new PhysicalFileSystem("C:\\src\\StartupService\\maindirectory"); 
      var options = new FileServerOptions 
      { 
       EnableDefaultFiles = true, 
       FileSystem = physicalFileSystem, 
       StaticFileOptions = 
       { 
        FileSystem = physicalFileSystem, 
        ServeUnknownFileTypes = true 
       }, 
       // DefaultFilesOptions = {DefaultFileNames = new[] {"index.html"}} 
      }; 
      app.UseFileServer(options); 

어떤 생각이 어떻게 자기 OWIN에서 VS2017로 만든 각도 2를 호스트하는? 당신의 도움을 주셔서 감사합니다.

답변

0

@ ". \ Public"과 같은 상대 경로를 PhysicalFileSystem 개체에 전달해보십시오.

다음은 확장 도우미입니다.

public static class FileServerConfig 
    { 
     internal static void ServeFiles(this IAppBuilder app, string path = @".\Public") 
     { 
      try 
      { 
       var fileServerOptions = new FileServerOptions() 
       { 
        EnableDefaultFiles = true, 
        EnableDirectoryBrowsing = false, 
        RequestPath = new PathString(string.Empty), 
        FileSystem = new PhysicalFileSystem(path) 
       }; 

       fileServerOptions.StaticFileOptions.ServeUnknownFileTypes = true; 

       app.UseFileServer(fileServerOptions); 
      } 
      catch (System.Exception) 
      { 
       // Serilog.Log.Fatal("Cannot locate Public folder"); // Logging 
      } 
     } 
    } 

앱에 새로운 클래스에 위의 코드를 추가하고 Startup.cs 할에서 다음 중 하나를

app.ServeFiles(); 

또는

또한
app.ServeFiles(@".\customPath"); 

; web.config에 Owin 핸들러를 추가하십시오.

<handlers> ... <add name="Owin" verb="" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb" /> </handlers>