开发者

HttpContext is null when request is not coming from a browser

开发者 https://www.devze.com 2023-01-28 04:58 出处:网络
We have a server application that loads into the IIS worker process. When we request a url from a browser, our application can see the current httpcontext but it is null when we use a tool that sends

We have a server application that loads into the IIS worker process. When we request a url from a browser, our application can see the current httpcontext but it is null when we use a tool that sends some upload requests using .net WebRrquest.Create method.

What we are trying to solve is tha开发者_开发技巧t when a request comes from our tool, we send some extra parameters in its headers so that our applicatin at the server end can understand that this request needs some special handling.

What should be the approach that we should follow?


Have you considered using SimpleWorkerRequest

See an example here


Is is an actuall http request, or is it spoofed inside the IIS process? I would recommend using HttpWebRequest (or simpler: WebClieny) so that your request is fully valid. You can still set headers etc.

At the simplest level:

using(var client = new WebClient()) {
    // add headers etc
    client.DownloadString(url);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消