2016-08-24 190 views
1

我的網絡API拋出的錯誤,當我運行it.It說無法連接到遠程服務器

服務器錯誤「/」應用

所以,修復它我在HelpPageAreaRegistration.cs的RegisterArea方法中更改了Help/{action}/{apiId}{Controller}/{action}/{apiId}。以下是方法。現在

public override void RegisterArea(AreaRegistrationContext context) 
{ 
    context.MapRoute(
     "HelpPage_Default", 
     "Help/{action}/{apiId}", 
     new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 

    HelpPageConfig.Register(GlobalConfiguration.Configuration); 
} 

,這個問題是固定的,但是當我跑我的web應用程序,它給了我錯誤說couldnot連接到遠程server.Below是從Web應用程序調用的API就行了。

HttpResponseMessage response = await Http.PostAsJsonAsync("Account/Authenticate", model).ConfigureAwait(false); 

和網絡API,

[Route("Authenticate")] 
[HttpPost] 
[ValidateModel] 
public AuthResponseServiceModel Authenticate(AuthRequestServiceModel sm) 
{ 
    //code 
} 

完全不知道我在API修復如何打破Web應用程序和Web API之間的連接。 請讓我知道我是否缺少任何東西。

+1

假設您啓用了屬性路由,您的控制器上是否有[RoutePrefix(「Account」)]? – Developer

+0

是的,我有.. – user3092654

+0

可能是一個非常愚蠢的懷疑;您是否嘗試爲「/」Http.PostAsJsonAsync(「/ Account/Authenticate」,模型)添加前綴 – Developer

回答

0

得到它解決了.. 只是條代替以下功能Routeconfig.cs

routes.MapRoute( 名稱: 「默認」, 網址: 「{控制器}/{行動}/{ID}」, 默認值:new {controller =「Help」,action =「Index」,id = UrlParameter.Optional} );

下面溫控功能

routes.MapRoute( 名: 「默認」, URL: 「」, 的默認值:新{控制器= 「幫助」,動作= 「索引」} ).DataTokens = new RouteValueDictionary(new {area =「HelpPage」});

並將RegisterArea方法中的更改還原爲原始。