asp.net - WebAPI returning UnAuthorized if missing Header Value -
using aps.net mvc 4 webapi
each request must have header called "version" if doesn't or version low, need return unauthorized value client. i'm not sure how send response .
in baseapicontroller have this:
public abstract class baseapicontroller : apicontroller { public override system.threading.tasks.task<system.net.http.httpresponsemessage> executeasync(system.web.http.controllers.httpcontrollercontext controllercontext, system.threading.cancellationtoken cancellationtoken) { var versiontext = controllercontext.request.headers.getvalues("version").firstordefault(); if(!string.isnullorempty(versiontext)) int.tryparse(versiontext, out _version); ***here*** if _version <1 return unauthorized ???? **** return base.executeasync(controllercontext, cancellationtoken); } }
i'm not sure if that's acceptable way of doing can try out returning task give response want:
// if version < 1
return new task<httpresponsemessage>(() => return request.createresponse(httpstatuscode.unauthorized));
Comments
Post a Comment