本文整理汇总了C#中IHttpHandler类的典型用法代码示例。如果您正苦于以下问题:C# IHttpHandler类的具体用法?C# IHttpHandler怎么用?C# IHttpHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IHttpHandler类属于命名空间,在下文中一共展示了IHttpHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUpSessionState
internal static void SetUpSessionState(HttpContextBase context, IHttpHandler handler, ConcurrentDictionary<Type, SessionStateBehavior?> cache)
{
WebPageHttpHandler webPageHandler = handler as WebPageHttpHandler;
Debug.Assert(handler != null);
SessionStateBehavior? sessionState = GetSessionStateBehavior(webPageHandler.RequestedPage, cache);
if (sessionState != null)
{
// If the page explicitly specifies a session state value, return since it has the most priority.
context.SetSessionStateBehavior(sessionState.Value);
return;
}
WebPageRenderingBase page = webPageHandler.StartPage;
StartPage startPage = null;
do
{
// Drill down _AppStart and _PageStart.
startPage = page as StartPage;
if (startPage != null)
{
sessionState = GetSessionStateBehavior(page, cache);
page = startPage.ChildPage;
}
}
while (startPage != null);
if (sessionState != null)
{
context.SetSessionStateBehavior(sessionState.Value);
}
}
示例2: ReleaseHandler
public void ReleaseHandler(IHttpHandler handler)
{
IDisposable d = handler as IDisposable;
if (d != null)
d.Dispose();
}
示例3: VerifyAndProcessRequest
protected override void VerifyAndProcessRequest(IHttpHandler handler, HttpContextBase context)
{
Precondition.Require(handler, () => Error.ArgumentNull("handler"));
Precondition.Require(context, () => Error.ArgumentNull("context"));
handler.ProcessRequest(context.Unwrap());
}
示例4: HttpServer
public HttpServer(IHttpHandler app, HttpServerSettings settings)
{
if (app == null) throw new ArgumentNullException("app");
if (settings == null) throw new ArgumentNullException("settings");
// init asp.net host
if (settings.AspNetHost)
{
var appHost = new AppHost(settings);
appHost.Init();
}
IHttpListener listener;
switch (settings.Mode)
{
case HttpServerMode.TcpListener:
listener = new TcpListenerImpl(app, settings);
break;
case HttpServerMode.HttpListener:
listener = new HttpListenerImpl(app, settings);
break;
default:
throw new ArgumentOutOfRangeException();
}
_listener = listener;
_listener.Start();
_listenerThread = new Thread(Listen);
_listenerThread.Start();
}
示例5: ReleaseHandler
public void ReleaseHandler(IHttpHandler httphandler)
{
if (httphandler is HandlerWrapper)
{
((HandlerWrapper) httphandler).ReleaseWrappedHandler();
}
}
示例6: RegisterUserControl
private static void RegisterUserControl(IHttpHandler handler)
{
var page = handler as Page;
Action<Control> RegisterUserControl = null;
Action<ControlCollection> RegisterControls = null;
EventHandler onPageLoad = null;
onPageLoad = (sender, e) =>
{
RegisterControls = controls =>
{
foreach (Control c in controls)
RegisterUserControl(c);
};
RegisterUserControl = control =>
{
var userControl = control as UserControl;
if (userControl != null)
Kernel.Compose(userControl);
RegisterControls(control.Controls);
};
RegisterControls(page.Controls);
page.Load -= onPageLoad;
};
if (page != null)
page.Load += onPageLoad;
}
示例7: GetHttpHandler
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new AssetManagerRouteHttpHandler(_url);
return _httpHandler;
}
示例8: ReleaseHandler
public void ReleaseHandler(IHttpHandler handler)
{
if (!this._handler.IsReusable)
{
this._handler = null;
}
}
示例9: HttpHandlerFactory
static HttpHandlerFactory()
{
DefaultHttpHandler = new StaticFileHttpHandler();
DirectoryHttpHandler = AspNetHandler = new AspNetHttpHandler();
var cache = new Dictionary<string, IHttpHandler>();
handlers = new Dictionary<string, IHttpHandler>();
foreach (HttpHandlerElement handlerElement in ServerConfiguration.HttpHandlers)
{
try
{
if (handlerElement.Extension == "*")
{
DefaultHttpHandler = GetOrCreateHttpHandler(handlerElement.HandlerType, cache);
continue;
}
if (handlerElement.Extension == "/")
{
DirectoryHttpHandler = GetOrCreateHttpHandler(handlerElement.HandlerType, cache);
continue;
}
if (!handlers.ContainsKey(handlerElement.Extension))
{
handlers[handlerElement.Extension] = GetOrCreateHttpHandler(handlerElement.HandlerType, cache);
}
}
catch (Exception ex)
{
log.ErrorFormat("Can not create HttpHandler '{0}'.\r\n{1}", handlerElement.HandlerType, ex);
}
}
}
示例10: TestHttpServer
public TestHttpServer(FixedPortAddress address, IHttpHandler handler)
{
Url = address.Url;
this.handler = handler;
Instance = this;
}
示例11: HttpListenerImpl
public HttpListenerImpl(IHttpHandler app, HttpServerSettings settings)
{
_app = app;
_settings = settings;
_listener = new HttpListener();
_listener.Prefixes.Add(string.Format(@"http://+:{0}/", settings.Port));
}
示例12: GetHttpHandler
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new ConfigurationRouteHttpHandler();
return _httpHandler;
}
示例13: ReleaseHandler
public override void ReleaseHandler(IHttpHandler handler)
{
if (!(handler is SourceViewer))
{
base.ReleaseHandler(handler);
}
}
示例14: GetHttpHandler
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new RestServiceRouteHttpHandler(_type, _url);
return _httpHandler;
}
示例15: Call
public async Task<object> Call(IHttpHandler httpHandler, string baseUrl, Dictionary<string, object> arguments, HttpApiInstrumenter apiInstrumenter = null)
{
var request = new HttpApiRequest { Url = Url.CreateUrl(baseUrl), Method = Method, Headers = Headers.ToList() };
Action<Func<IHttpArgumentHandler, string, object, Task>> applyArguments = async applier =>
{
foreach (var item in ArgumentHandlers)
{
var name = item.Key;
object argument;
if (arguments.TryGetValue(name, out argument))
{
var handler = item.Value;
await applier(handler, name, argument);
}
}
};
applyArguments(async (handler, name, argument) => await handler.ApplyArgument(request, name, argument));
Func<HttpApiRequest, Task<HttpApiResponse>> call = async apiRequest => await httpHandler.Call(apiRequest);
HttpApiResponse response;
if (apiInstrumenter != null)
response = await apiInstrumenter(request, call);
else
response = await call(request);
applyArguments(async (handler, name, argument) => await handler.ApplyArgument(response, name, argument));
return await ResponseHandler.HandleResponse(request, response);
}