我的服务栈实现面临问题,我已经让以下请求url调用我的服务并实现了一个perfmon类和perfmonservice类
[RestService("/perfmon/application/{appliationId}")]
[RestService("/perfmon/application/{appliationId}/{countername}")]
[RestService("/perfmon/user/{userId}")]
[RestService("/perfmon/user/{userId}/{countername}")]
Run Code Online (Sandbox Code Playgroud)
现在,当我将调用任何URL时,它将调用以下函数
public override object OnGet(Perfmon request)
{
return base.OnGet(request);
}
Run Code Online (Sandbox Code Playgroud)
那么我怎么能在这里决定哪个URL进行了此调用,weather servicestack提供了任何特定的方法来执行此操作,或者我需要通过检查属性来编写手动逻辑?
提前致谢
只需检查请求DTO以查看填充了哪些字段,即
if (request.applicationId != null && request.countername != null) #2
if (request.userId != null && request.countername != null) #4
if (request.applicationId != null) #1
if (request.userid != null) #3
Run Code Online (Sandbox Code Playgroud)
另请注意,用户也可以使用查询字符串填充请求dto,即如果他们通过以下方式呼叫您:
/perfmon/application/1/countername?userId=2
Run Code Online (Sandbox Code Playgroud)
然后将填充所有字段.最后,您可以检索有关请求的信息,例如用于调用请求的绝对URI:
base.RequestContext.AbsoluteUri
Run Code Online (Sandbox Code Playgroud)
最后,您可以使用以下命令获取IHttpRequest对象:
var httpReq = base.Request; //or with base.RequestContext.Get<IHttpRequest>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1096 次 |
| 最近记录: |