【发布时间】:2014-01-17 08:02:05
【问题描述】:
我在 C# 中有一个非常基本的 RESTful WCF 服务,如下所示。
public SchoolList[] GetSchoolList(string authenticationToken, string term, string stateID, string schoolTypes)
{
if (!TokenAuthenticator.Authenticate(authenticationToken, out marketPlaceIdInner))
{
//throw new ApplicationException(Constants.InvalidAuth); //**line 1**
}
try
{
SchoolList[] returnedschoolList = schoolManagementCacheServiceClient.GetSchoolSuggestions(term, schoolTypes, stateID).ToArray<SchoolList>();
return returnedschoolList;
}
finally
{
schoolManagementCacheServiceClient.Close();
}
}
它运行良好,我想要实现的是当控件到达 第 1 行时,我想返回一个简单的错误字符串和 HTTP 状态代码为 403 即禁止。
如何以最少的代码实现它?我参考了其他代码示例,它们太大而且有点复杂。
【问题讨论】:
标签: c# .net wcf http-status-code-403