2017-10-12 8 views
-1

これは私の問題です。私は3つの部分を持つプロジェクトソリューションを継承しました。 Sharepointページプロジェクト、APIプロジェクト、SSISプロジェクト私は必要に応じて追加や学習をしていますが、今は指導が必要です。最近私は2つの標準MVC 4 WebページをWEB Apiプロジェクトに追加して2つの新しいテーブルをCRUDしました。その後、新しいWeb APIエンドポイントを追加して、新しいデータの一部をクエリして、新しい分析ページをSharepointプロジェクトに追加しました。私の問題は、どのようにルートを設定しても、エンドポイントに応答させることができないということです。ルーティング、Web API、ASP MVCを行うエンジンが2つ(またはそれ以上)あることがわかりました。私はこのプロジェクトで2つのスタイルを混在させてしまったというのが私の問題です。C#、ASP MVC 4、Web API、 "タイプがコントローラの名前と一致するものが見つかりませんでした。"

ここ

は私WebApiConfigです:

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 } 
     ); 
    } 
} 
} 

` そして、私のRouteConfig:

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); 
    } 
} 
} 

そして、私の最新のコントローラ...

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の内容に追いつき、Web開発とMVC 4と5に追いついています。私が最近継承したプロジェクトには、最高のドキュメントはありません。 (驚き)。私が作成したWebアプリケーション用のコードを追加しながら、私はこの手順に従った。変更を加える。プロジェクトをクリーンアップします。プロジェクトを再構築する。クリーンソリューション。ソリューションを再構築します。テストのためにIDE内でソリューションを実行します。これは、私が構築した2 mvcのWebページでうまくいきました。新しいAPIを追加すると、エンドポイントにアクセスする方法がわからないため、手順を変更しました。私は試みた:変更します。プロジェクトをクリーンアップします。プロジェクトを再構築する。クリーンソリューション。ソリューションを再構築し、予期せぬ結果を得ました。その後、Chromeをスタンドアロンで開き、現在動作しているAPIエンドポイントにアクセスしました。うまくいきましたが、上記で作成した新しいエンドポイントを試したところ、上記の結果が得られました。最終的には、既存の動作中のAPIを実行/変更しようとしましたが、変更が見られないことがわかりました。最後に私の新しいソリューションを展開して公開し、変更が現れました。私は上記のコードに正確に戻って、私の新しいソリューションを展開して公開し、新しいエンドポイントが応答しました。私の現在の質問は、ソリューション内の2つのプロジェクト(SharepointソリューションとWEB MVC 4 PAGES/API)を変更するときです。すべての変更がIDE内で発生するのを確認する最小限のプロセスは何ですか?毎回展開して公開する必要がありますか? deployが常に必要な場合、なぜそれが公開プロセスの一部ではないのですか?

関連する問題