2017-02-17 56 views
0

我正在从angularjs控制器调用web api方法,如下所示。为什么web api调用在部署iis后返回html页面

$http.get('../api/Home/AppLogin').then(function (response) { 
    alert(response.data); 
, function (error) { 
    alert('Error: ' + error.message); 
}) 

我使用angularJs路由如下:

var cioTrack = angular.module('CIOTrack', ['ngRoute', 'ngSanitize']); 
//Define Routing for the application 
cioTrack.config(
function ($routeProvider, $locationProvider) { 
    $locationProvider.hashPrefix(''); 

    $routeProvider. 
     when('/', { 
      templateUrl: 'Index.html', 
      controller: 'IndexController' 
     }). 
     when('/Notify', { 
      templateUrl: 'Views/Notify.html', 
      controller: 'NotifyController' 
     }). 
     when('/Report', { 
      templateUrl: 'Views/Report.html', 
      controller: 'ReportController' 
     }) 

    $locationProvider.html5Mode(true); 
}); 

在配置我有以下规则:

<rewrite> 
    <rules> 
    <rule name="rewriteRule" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="/" /> 
    </rule> 
    </rules> 
</rewrite> 

的Web API控制器的方法:

[Route("api/Home/AppLogin")] 
[HttpGet] 
public string AppLogin() 
    { 
     return "some string"; 
    } 

这是当我从vi运行时工作正常sual工作室。但在web服务器(IIS)上部署代码后,api调用返回完整的html。成功的功能

输出,如果我从Visual Studio中运行:我与字符串“一些字符串”成功的功能

输出警报,如果我的IIS Web服务器是我得到完整的HTML页面的消息在部署后运行。

IIS版本是7.5 我已在IIS Web服务器上安装了URL重写。

请告诉我这里有什么问题?

回答

0

我通过在重写规则中添加一个条件解决了这个问题。分享给他人。

<add input="{URL}" negate="true" pattern="/API/" /> 
相关问题