我有两个应用程序和一个数据库,一旦部署到单独服务器上的IIS,我就会尝试使用它们的所有功能。目标是使用户最初通过Windows进行身份验证,然后仍然让服务进行通信。我们希望保留用户EID作为每个步骤/请求的身份,但是,在这种情况下,我们必须使用某种通用AppPool帐户,我认为我们对此持开放态度。
当我从本地启动的应用程序中的IIS Express本地调用Odata Web API时,没有错误。该数据库是已运行一段时间的MS SQL Server数据库,包含一小部分应用程序使用的数据,并在使用Telerik Fiddler等查询时按预期方式将数据返回到 Application 1 。
应用程序和数据库都在单独的服务器上运行。
基本请求方案为:
客户端设备(此处已根据AD对用户进行身份验证)-> GET->应用程序2-> GET->应用程序1-> SQLQUERY / DbContextRequest-> SQL Server
因此,客户端设备(从移动应用程序)发出获取请求,该请求被发送到应用程序2 的API端点,然后该API端点调用应用程序1 API端点,用于从数据库检索数据并返回到应用程序2 ,在该应用程序中,在将数据发送回客户端设备之前,会进行一些数据组织。
明细:
应用程序1:使用Odata控制器接收请求的ASP.NET Web API
应用程序2:使用 RestSharp 发送请求的ASP.NET Web API。
到目前为止,应用程序1 已部署到其服务器上数月没有问题,但这是我们首次尝试从另一个Web服务( >应用程序2 )。
应用程序2 可以毫无问题地调用由我们公司托管的其他Web服务,只有这个(应用程序1 )返回“未经授权”。
故障应用程序(应用程序1 )当前已部署到IIS。当我从本地运行IIS Express的应用程序2的应用程序计算机向应用程序1发送GET请求时,数据将按预期返回。从本地计算机使用Fiddler也会从应用程序1 返回数据,而不会出现问题。
但是,一旦我将应用程序2 部署到IIS,带有Odata控制器的应用程序(应用程序1 )就会对“ 应用程序”发送的任何请求返回“未经授权” 2 部署到 Application 1 。
我已使用 log4Net 并确定我是否使用模拟,未经授权,即使是以同一用户身份发送请求(已通过日志验证)还是AppPool身份验证也是如此。我的AD帐户和AppPool ID帐户都具有对返回“未经授权”的 Application 1 文件夹的完全访问权限。
我正在使用 RestSharp 库发送请求:
[HttpGet]
[ResponseType(typeof(WorkOrderModel))]
public IHttpactionResult GetWorkOrderDEBUG()
{
const string id = "1000";
var client = new RestClient(Constants.ODATA_WEBSERVICEDOMAIN)
{
// Authentication needed when querying ODATA
Authenticator = new NtlmAuthenticator()
};
var request = new RestRequest(Constants.ODATA_WEBSERVICE_PATH + "(" + id + ")",Method.GET);
// add http header or request to remove odata metadata
request.AddHeader("accept","application/json; odata.metadata=none");
request.RequestFormat = DataFormat.Json;
// Logging for debugging after deployment
log.Debug("CURRENT IDENTITY: " + Environment.username);
log.Debug("CURRENT OTHER IDENTITY: " + system.security.Principal.WindowsIdentity.getcurrent().Name);
log.Debug("CURRENT MAYBE IDENTITY: " + GetUser());
log.Debug("BaseUrl Path and Query: " + client.BaseUrl.PathAndQuery.ToString());
log.Debug("Authenticator: " + client.Authenticator.ToString());
log.Debug("Request Format: " + request.RequestFormat.ToString());
log.Debug("Resource: " + request.Resource.ToString());
// RestSharp execute request
var response = client.Execute(request);
// Logging for debugging after deployment
if (response.ErrorMessage != null)
{
log.Debug("ErrorMessage: " + response.ErrorMessage.ToString());
}
if (response.ErrorException != null)
{
log.Debug("ErrorException.Message: " + response.ErrorException.Message.ToString());
if (response.ErrorException.InnerException != null)
{
log.Debug("InnerException.Message: " + response.ErrorException.InnerException.Message.ToString());
}
}
if (response.Content != null)
{
log.Debug("Content: " + response.Content.ToString());
}
log.Debug("ContentType: " + response.contenttype.ToString());
//log.Debug("Headers: " + response.Headers.ToString());
//log.Debug("Request: " + response.Request.ToString());
log.Debug("ResponseStatus: " + response.ResponseStatus.ToString());
log.Debug("ResponseURI-Path and Query: " + response.ResponseUri.PathAndQuery.ToString());
log.Debug("ResponseURI-OriginalString: " + response.ResponseUri.OriginalString.ToString());
log.Debug("ResponseURI-Segments: " + response.ResponseUri.Segments.ToString());
log.Debug("Server: " + response.Server.ToString());
log.Debug("Status Code: " + response.StatusCode.ToString());
log.Debug("Status Description: " + response.StatusDescription.ToString());
var content = response.Content;
//if (content != null)
//{
// log.Debug(content.ToString());
//}
var workOrder = JsonConvert.DeserializeObject<WorkOrderModel>(content);
log.Debug(workOrder.ToString());
return Ok(workOrder);
}``
这是我的 Web配置:
<system.web>
<authentication mode="Windows" />
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>
<identity impersonate="true" />
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.6.1" />
<httpruntime targetFramework="4.6.1" />
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule,Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule,Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule,Elmah" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedmodeConfiguration="false" />
我认为webservice / server / controller / method路径是可以的,因为当在服务器上使用telek的Fiddler在IIS上直接查询 Application 1 的Odata Web API Controller时,它们可以正常工作我的本地计算机或SwaggerUI,所以我不在这里...
以下是一些错误日志:
DEBUG 2019-11-15 17:00:56,786 1397487ms
Controller GetWorkOrder - CURRENT IDENTITY: myid123
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - CURRENT OTHER IDENTITY: MBULOGIN\myid123
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - BaseUrl Path and Query: /app/odata/
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - Authenticator: RestSharp.Authenticators.NtlmAuthenticator
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - Default Parameters:System.Collections.Generic.List`1[RestSharp.Parameter]
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - Parameters: System.Collections.Generic.List`1[RestSharp.Parameter]
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - Request Format: Json
DEBUG 2019-11-15 17:00:56,786 1397487ms Controller GetWorkOrder - Resource: WorkOrders(100000)
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Content: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>401 - Unauthorized: access is denied due to invalid credentials.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana,sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>401 - Unauthorized: access is denied due to invalid credentials.</h2>
<h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>
</fieldset></div>
</div>
</body>
</html>
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - ContentType: text/html
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Headers: System.Collections.Generic.List`1[RestSharp.Parameter]
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Request: RestSharp.RestRequest
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - ResponseStatus: Completed
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - ResponseURI-Path and Query: /app/odata/WorkOrders(1000000)
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - ResponseURI-OriginalString: https://example.com/app/odata/WorkOrders(1000000)
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - ResponseURI-Segments: System.String[]
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Server: microsoft-IIS/8.5
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Status Code: Unauthorized
DEBUG 2019-11-15 17:00:56,802 1397503ms Controller GetWorkOrder - Status Description: Unauthorized
在发送没有模拟的GET请求时,log4net的错误日志与上面的相同,只是身份更改为AppPool的身份。
我不明白与从IIS Express中运行该应用程序的计算机本地发出的请求相比,从IIS向应用程序1 的Odata Web Api控制器发出的请求有何不同?因此,在使用模拟之后。一旦被模拟,在本地运行没有问题的同一帐户就是“未授权”。
我已经在IIS GUI中检查了应用程序的授权策略,两个IIS实例都允许Windows Auth。
这是服务器/ IIS设置吗?如果是这样,针对哪个应用程序?我真的不确定要研究什么,似乎从IIS发出的 Application 2 来自IIS的信息与GET请求一起发送要求未获授权的请求...但是可能是什么?