I am writing an authorization function in Custom HTTP Module.This is my code:
private bool CheckAuthorization(HttpContext context)
{
string auth = context.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(auth) || auth != "123")
{
context.Response.StatusCode = -404;//HttpStatusCode.MethodNotAllowed;
context.Response.Write("404 Not allowed!");
//webOperationContext.OutgoingResponse.StatusCode = HttpStatusCode.MethodNotAllowed;
}
return true;
}
My develop enviroment is:C# + .NET Framwork 4.0 + Visual Studio 2013 + WCF.My purpose is: When checked authorization failed,the request should not invoke the WCF method,and return a 404 method not allowed error.It is still invoke WCF method right now through return the error tips.Thank you!