我创建了一个web应用程序并为API创建了APIController我使用我的自定义ApiResponse它在我点击F5并使用visual studio在iisexpress中运行时工作正常。
但是,当我在IIS管理器中部署应用程序时,它向我显示了此错误
处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误的模块“ManagedPipelineHandler”
我已经尝试过这个来解决这个错误
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
public class ApiResponse
{
[DataMember]
public string Version { get { return "1.2.3"; } }
[DataMember]
public int StatusCode { get; set; }
[DataMember(EmitDefaultValue = false)]
public string ErrorMessage { get; set; }
[DataMember(EmitDefaultValue = false)]
public object Result { get; set; }
public ApiResponse(HttpStatusCode statusCode, object result = null, string errorMessage = null)
{
StatusCode = (int)statusCode;
Result = result;
ErrorMessage = errorMessage;
}
}
public class WrappingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
return BuildApiResponse(request, response);
}
private static HttpResponseMessage BuildApiResponse(HttpRequestMessage request, HttpResponseMessage response)
{
object content;
string errorMessage = null;
if (response.TryGetContentValue(out content) && !response.IsSuccessStatusCode)
{
HttpError error = content as HttpError;
if (error != null)
{
content = null;
errorMessage = error.Message;
errorMessage = string.Concat(errorMessage, error.ExceptionMessage, error.StackTrace);
}
}
var newResponse = request.CreateResponse(response.StatusCode, new ApiResponse(response.StatusCode, content, errorMessage));
foreach (var header in response.Headers)
{
newResponse.Headers.Add(header.Key, header.Value);
}
return newResponse;
}
}