2017-10-12 10 views
-1

여기 내 문제가 있습니다. 나는 3 조각을 가진 프로젝트 해결책을 물려 받았다. 셰어 포인트 페이지 프로젝트, API 프로젝트 및 SSIS 프로젝트 나는 필요에 따라 추가하고 배우고 있었고, 이제 나는 도움이 필요하다. 가장 최근에는 2 개의 표준 MVC 4 웹 페이지를 WEB API 프로젝트에 추가하여 CRUD 2 개의 새 테이블을 만들었습니다. 그런 다음 SharePoint 분석에 추가 할 새 분석 페이지에 대해 새 데이터의 일부를 쿼리하는 새 웹 API 끝점을 추가했습니다. 내 문제는 내가 어떻게 엔드 포인트를 응답 할 수없는 라우트를 구성하더라도 상관 없다는 것입니다. 오늘 라우팅, 웹 API 및 ASP MVC를 수행하는 엔진이 2 개 (또는 그 이상) 있다는 것을 알게되었고 프로젝트에서 2 가지 스타일을 혼합했다는 사실이 내 문제라고 생각합니다.C#, ASP MVC 4, 웹 API, "명명 된 컨트롤러와 일치하는 유형이 없습니다 ..."

내 RouteConfig

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web.Http; 
using System.Web.Http.Cors; 
using WebApiContrib.Formatting.Jsonp; 

namespace API_MetricsWarehouse 
{ 
public static class WebApiConfig 
{ 
    public static void Register(HttpConfiguration config) 
    { 
     // Web API configuration and services 

     // enable CORS 
     var cors = new EnableCorsAttribute("*", "*", "*"); 
     config.EnableCors(cors); 

     // jsonp 
     var jsonpFormatter = new JsonpMediaTypeFormatter(config.Formatters.JsonFormatter); 
     config.Formatters.Add(jsonpFormatter); 

     // Web API routes 
     config.MapHttpAttributeRoutes(); 
     config.Routes.MapHttpRoute(
      name: "Sites", 
      routeTemplate: "api/sites/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 

     config.Routes.MapHttpRoute(
      name: "ReportDates", 
      routeTemplate: "api/reportdates/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 

     config.Routes.MapHttpRoute(
      name: "SafetyDates", 
      routeTemplate: "api/safetydates/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 
    } 
} 
} 

` 그리고 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Routing; 

namespace API_MetricsWarehouse 
{ 
public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
} 
} 

그리고 내 Global.asax에

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Http; 
using System.Web.Mvc; 
using System.Web.Optimization; 
using System.Web.Routing; 

namespace API_MetricsWarehouse 
{ 
public class WebApiApplication : System.Web.HttpApplication 
{ 
    protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 
     GlobalConfiguration.Configure(WebApiConfig.Register); 
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
     RouteConfig.RegisterRoutes(RouteTable.Routes); 
     BundleConfig.RegisterBundles(BundleTable.Bundles); 
    } 
} 
} 

여기 내 WebApiConfig입니다

그리고 내 최신 컨트롤러는 ...

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.Entity; 
using System.Data.Entity.Infrastructure; 
using System.Linq; 
using System.Net; 
using System.Net.Http; 
using System.Web.Http; 
using System.Web.Http.Description; 
using API_MetricsWarehouse.Models; 
using System.Web.Http.Cors; 


namespace API_MetricsWarehouse.Controllers 
{ 
public class SafetyDatesController : ApiController 
{ 
    private MetricsWarehouseEntities db = new MetricsWarehouseEntities(); 

    // GET: api/SafetyDates 
    public IQueryable<SafetyDates> GetSafetyDates() 
    {    
     var result = db.SafetyAnalysis1.AsQueryable(); 

     result = result 
      .GroupBy(x => x.YearMonth) 
      .Select(x => x.FirstOrDefault()) 
      .Distinct() 
      .OrderByDescending(x => x.YearMonth); 

     return result 
      .AsEnumerable() 
      .Select(a => 
       new SafetyDates 
       { 
        SafetyYearMonth = ((DateTime)a.YearMonth).ToString("yyyy MMM") 
       }) 
      .AsQueryable(); 


    } 

    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      db.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

} 
} 

새로운 컨트롤러는 거의 ReportDates 컨트롤러하지만 엔드 포인트의 탄소 사본이 발생하지 않습니다됩니다. (ReportDates는 여전히 훌륭하게 작동합니다 ...) 누구든지 나를 풀 수 있도록 도와 줄 수 있습니까? 차라리 이전 프로젝트로 돌아가서 MVC 페이지를 꺼내 다른 프로젝트에 넣지는 않겠지 만 그 것이 유일한 방법 인 경우 수행 할 것입니다 ...

+1

시도하려는 URL은 무엇입니까? – Shyju

+0

https://internalSite.com/_metrics/api/safetydates : broken https://internalSite.com/_metrics/api/reportdates : works – MultiWolf

답변

0

그래서 내 문제에 대해 좀 더 자세히 설명합니다. 저는 1996 년부터 Microsoft 제품에서 일해 왔습니다. 저는 Foxpro와 VB6에서 광범위하게 일했으며 지난 몇 년 동안 VC#에서 일해 왔습니다. 여전히 2013 년과 2015 년 IDE의 기능을 포착하고 웹 개발 및 MVC 4와 5를 따라 잡습니다. 최근에 제가 상속 한 프로젝트에는 최고의 문서가 없습니다. (놀람). 웹 응용 프로그램에 대한 코드를 추가하면서이 절차를 따랐습니다. 변경하십시오. 프로젝트를 청소하십시오. 프로젝트를 다시 빌드하십시오. 깨끗한 솔루션. 솔루션을 다시 빌드하십시오. 테스트를 위해 IDE 내에서 솔루션을 실행하십시오. 이것은 내가 만든 2 mvc 웹 페이지에 대해 잘 작동합니다. 새 API를 추가하고 나면 끝점에 액세스하는 방법을 잘 모르기 때문에 절차가 변경되었습니다. 나는 시도했다 : 변화를 만든다. 프로젝트를 청소하십시오. 프로젝트를 다시 빌드하십시오. 깨끗한 솔루션. 솔루션을 다시 빌드하고 예기치 않은 결과가 발생했습니다. 그런 다음 Chrome 독립형을 열고 현재 작동중인 API 끝점에 액세스했습니다. 괜찮 았지만 위에서 작성한 새로운 엔드 포인트를 시도했을 때 위의 결과가 나타납니다. 결국 나는 기존의 작동중인 API를 실행/변경하려고했지만 변경 사항을 볼 수 없다는 것을 알았습니다. 마지막으로 새로운 솔루션을 배포하고 게시하여 변경 사항이 나타났습니다. 나는 위의 코드로 정확하게 돌아가서 새 솔루션을 배포하고 게시했으며 NEW 끝 점이 응답했습니다. 내 현재 질문은 솔루션 내에서 2 개의 프로젝트 (Sharepoint 솔루션 및 WEB MVC 4 PAGES/API)를 변경할 때 IDE 내의 모든 변경 사항을 확인하는 최소 프로세스는 무엇입니까? 매번 배포하고 게시해야합니까? 배포가 항상 필요한 경우 게시 프로세스의 일부가 아닌 이유는 무엇입니까?