0

클라이언트 코어 종속성 NPM, Bower, Gulp를 사용하여 ASP.NET Core MVC 및 AngularJS로 프로젝트를 만들었습니다. wwwroot 폴더에 생성 된 index.html 페이지는 기본적으로 표시되지 않습니다.ASP.NET 코어 MVC index.html이 기본 페이지로 설정되지 않았습니다.

은 index.html을

<!DOCTYPE html> 
<html ng-app="myQuotesApp"> 
<head> 
<meta charset="utf-8" /> 
<title>My Quotes App</title> 
<script src="lib/angular/angular.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-resource.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-route.js"></script> 
<script src="app.js"></script> 
</head> 
<body ng-cloak> 
<div ng-controller="quotesController"> 
    <h2>List Of Quotes</h2> 

    <ul> 
     <li ng-repeat="quote in quotes"> 
      <p>"{{quote.Content}}" - {{quote.Author}}</p> 
     </li> 
    </ul> 
</div> 

</body> 
</html> 

Startup.cs는

public class Startup 
{ 
    // This method gets called by the runtime. Use this method to add services to the container. 
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 
    public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddMvc(); 
    } 
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(); 
     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
     } 
     //app.Run(async (context) => 
     //{ 
     // await context.Response.WriteAsync("Hello World!"); 
     //}); 
     app.UseMvc(); 
    } 
} 

project.json

 { 
    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.0.1", 
     "type": "platform" 
    }, 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.1" 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

파일

(function() { 
    'use strict'; 
    angular.module('MyQuotesApp', [ 
     // Angular modules 
     'ngRoute', 
////////////////// 
     'ngResource', 
///////////////insert this ^^^^ 
     // Custom modules 
     "quotesService" 
     // 3rd Party Modules   
    ]); 
})(); 
을 app.js

quotesService.cs

(function() { 
'use strict'; 

var quotesService = angular.module('quotesService', ['ngResource']); 

quotesService.factory('Quotes', ['$resource', function ($resource) { 
    return $resource('/api/quotes/', {}, { 
     query: { method: 'GET', params: {}, isArray: true } 
    }); 
}]); 
})(); 

quotesController.js

(function() { 
    'use strict'; 

    angular 
     .module('myQuotesApp') 
     .controller('quotesController', quotesController); 

    quotesController.$inject = ['$scope','Quotes']; 

    function quotesController($scope, Quotes) { 

     $scope.quotes = Quotes.query(); 
     //$scope.title = 'quotesController'; 

     //activate(); 

     //function activate() { } 
    } 
})(); 

QuotesConroller.cs

namespace MyQuotesApp.api 
{ 
[Route("api/[controller]")] 
public class QuotesController : Controller 
{ 
    // GET: api/values 
    [HttpGet] 
    public IEnumerable<Quote> Get() 
    { 
     return new List<Quote> { 
      new Quote {ID=1, Content="abc", Author="abc123" }, 
      new Quote {ID=2, Content="abcd", Author="abcd123" }, 
      new Quote { ID=3, Content="abcde", Author="abcde123"} 
     }; 
     //return new string[] { "value1", "value2" }; 
    } 

    // GET api/values/5 
    [HttpGet("{id}")] 
    public string Get(int id) 
    { 
     return "value"; 
    } 

    // POST api/values 
    [HttpPost] 
    public void Post([FromBody]string value) 
    { 
    } 

    // PUT api/values/5 
    [HttpPut("{id}")] 
    public void Put(int id, [FromBody]string value) 
    { 
    } 

    // DELETE api/values/5 
    [HttpDelete("{id}")] 
    public void Delete(int id) 
    { 
    } 
} 
} 
+1

mvc에서는 기본 페이지를 설정하지 않고 라우팅 할 페이지를 결정하기 위해 – Baahubali

+0

을 사용합니다.이 데모는 wwwroot 폴더에있는 index.html을 사용하고 defauls로 작동하지만 내 코드에서는 작동하지 않습니다. –

+0

라우팅 클래스 – Baahubali

답변

0

당신은 당신에 대한 GET 요청을받을 때 수행 할 작업을 지정하는 조치를하지 않아도 루트 (/).

특정보기를 제공하지 않고 return View();를 지정 MVC에서
[HttpGet('/')] 
public IActionResult Index() 
{ 
    return View(); 
} 

, 그것은

+0

실행되었지만 index.html이 실행되지 않습니다 –

+0

@PrafulChauhan'index.html' 파일은 어디에 있습니까? 그것은 기본적으로'Views/Home/Index.html' 또는'Views/Index.html'에 있어야합니다. – James

+0

index.html은 wwwroot 접이식으로, asp.net 코어에 있으며 angularjs도 wwwroot 접힌 곳에 위치합니다. –

0

같은 문제 (이 경우 Index에서, 컨트롤러 메소드 이름)을 Action의 이름을 딴보기를 검색합니다 - index.html을 asp.net 코어 권장 사항에 따라 wwwroot 폴더에 있습니다. 이 페이지를 사이트의 기본값으로 표시하는 방법은 무엇입니까? 컨트롤러가 ".html"페이지를 제공하지 않는다는 것을 (MVC5에서) 알았습니까?

0

app.UseDefaultFiles()app.UseStaticFiles()을 추가해야합니다.

app.UsedefaultFiles()wwwrootfolder 내부 default.html을 또는 index.html을 같은 기본 파일을 찾습니다.