本文整理汇总了C#中HttpContextBase类的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase类的具体用法?C# HttpContextBase怎么用?C# HttpContextBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpContextBase类属于命名空间,在下文中一共展示了HttpContextBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginProcessRequest
protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state)
{
IHttpHandler httpHandler = GetHttpHandler(httpContext);
IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler;
if (httpAsyncHandler != null)
{
// asynchronous handler
// Ensure delegates continue to use the C# Compiler static delegate caching optimization.
BeginInvokeDelegate<IHttpAsyncHandler> beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState, IHttpAsyncHandler innerHandler)
{
return innerHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState);
};
EndInvokeVoidDelegate<IHttpAsyncHandler> endDelegate = delegate(IAsyncResult asyncResult, IHttpAsyncHandler innerHandler)
{
innerHandler.EndProcessRequest(asyncResult);
};
return AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, httpAsyncHandler, _processRequestTag);
}
else
{
// synchronous handler
Action action = delegate
{
httpHandler.ProcessRequest(HttpContext.Current);
};
return AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag);
}
}
示例2: GetTableWithFullFallback
internal static MetaTable GetTableWithFullFallback(IDataSource dataSource, HttpContextBase context) {
MetaTable table = GetTableFromMapping(context, dataSource);
if (table != null) {
return table;
}
IDynamicDataSource dynamicDataSource = dataSource as IDynamicDataSource;
if (dynamicDataSource != null) {
table = GetTableFromDynamicDataSource(dynamicDataSource);
if (table != null) {
return table;
}
}
table = DynamicDataRouteHandler.GetRequestMetaTable(context);
if (table != null) {
return table;
}
Control c = dataSource as Control;
string id = (c != null ? c.ID : String.Empty);
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
DynamicDataResources.MetaTableHelper_CantFindTable,
id));
}
示例3: Match
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
#endif
{
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
object value;
if (values.TryGetValue(parameterName, out value) && value != null)
{
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
int length = valueString.Length;
if (Length.HasValue)
{
return length == Length.Value;
}
else
{
return length >= MinLength.Value && length <= MaxLength.Value;
}
}
return false;
}
示例4: DoPostResolveRequestCache
internal void DoPostResolveRequestCache(HttpContextBase context) {
// Parse incoming URL (we trim off the first two chars since they're always "~/")
string requestPath = context.Request.AppRelativeCurrentExecutionFilePath.Substring(2) + context.Request.PathInfo;
// Check if this request matches a file in the app
WebPageMatch webpageRouteMatch = MatchRequest(requestPath, WebPageHttpHandler.GetRegisteredExtensions(), VirtualPathFactoryManager);
if (webpageRouteMatch != null) {
// If it matches then save some data for the WebPage's UrlData
context.Items[typeof(WebPageMatch)] = webpageRouteMatch;
string virtualPath = "~/" + webpageRouteMatch.MatchedPath;
// Verify that this path is enabled before remapping
if (!WebPagesDeployment.IsExplicitlyDisabled(virtualPath)) {
IHttpHandler handler = WebPageHttpHandler.CreateFromVirtualPath(virtualPath);
if (handler != null) {
// Remap to our handler
context.RemapHandler(handler);
}
}
}
else {
// Bug:904704 If its not a match, but to a supported extension, we want to return a 404 instead of a 403
string extension = PathUtil.GetExtension(requestPath);
foreach (string supportedExt in WebPageHttpHandler.GetRegisteredExtensions()) {
if (String.Equals("." + supportedExt, extension, StringComparison.OrdinalIgnoreCase)) {
throw new HttpException(404, null);
}
}
}
}
示例5: AddVersionHeader
/// <summary>
/// 在响应头中设置MVC版本信息
/// </summary>
/// <param name="httpContext"></param>
protected internal virtual void AddVersionHeader(HttpContextBase httpContext)
{
if (!DisableMvcResponseHeader)
{
httpContext.Response.AppendHeader(MvcVersionHeaderName, MvcVersion);
}
}
示例6: Validate
protected virtual bool Validate(HttpContextBase context)
{
if(context.User == null || context.User.Identity == null)
return false;
return context.User.Identity.IsAuthenticated;
}
示例7: BeginProcessRequest
protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state)
{
return SecurityUtil.ProcessInApplicationTrust(() =>
{
IController controller;
IControllerFactory factory;
ProcessRequestInit(httpContext, out controller, out factory);
IAsyncController asyncController = controller as IAsyncController;
if (asyncController != null)
{
// asynchronous controller
BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState)
{
try
{
return asyncController.BeginExecute(RequestContext, asyncCallback, asyncState);
}
catch
{
factory.ReleaseController(asyncController);
throw;
}
};
EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult)
{
try
{
asyncController.EndExecute(asyncResult);
}
finally
{
factory.ReleaseController(asyncController);
}
};
SynchronizationContext syncContext = SynchronizationContextUtil.GetSynchronizationContext();
AsyncCallback newCallback = AsyncUtil.WrapCallbackForSynchronizedExecution(callback, syncContext);
return AsyncResultWrapper.Begin(newCallback, state, beginDelegate, endDelegate, _processRequestTag);
}
else
{
// synchronous controller
Action action = delegate
{
try
{
controller.Execute(RequestContext);
}
finally
{
factory.ReleaseController(controller);
}
};
return AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag);
}
});
}
示例8: DetermineAutoCulture
private static CultureInfo DetermineAutoCulture(HttpContextBase context)
{
HttpRequestBase request = context.Request;
Debug.Assert(request != null); //This call is made from a WebPageExecutingBase. Request can never be null when inside a page.
CultureInfo culture = null;
if (request.UserLanguages != null)
{
string userLanguageEntry = request.UserLanguages.FirstOrDefault();
if (!String.IsNullOrWhiteSpace(userLanguageEntry))
{
// Check if user language has q parameter. E.g. something like this: "as-IN;q=0.3"
int index = userLanguageEntry.IndexOf(';');
if (index != -1)
{
userLanguageEntry = userLanguageEntry.Substring(0, index);
}
try
{
culture = new CultureInfo(userLanguageEntry);
}
catch (CultureNotFoundException)
{
// There is no easy way to ask if a given culture is invalid so we have to handle exception.
}
}
}
return culture;
}
示例9: SetCulture
internal static void SetCulture(Thread thread, HttpContextBase context, string cultureName) {
Debug.Assert(!String.IsNullOrEmpty(cultureName));
CultureInfo cultureInfo = GetCulture(context, cultureName);
if (cultureInfo != null) {
thread.CurrentCulture = cultureInfo;
}
}
示例10: Validate
public static void Validate(HttpContextBase httpContext, string salt) {
if (httpContext == null) {
throw new ArgumentNullException("httpContext");
}
_worker.Validate(httpContext, salt);
}
示例11: GetHtml
public static HtmlString GetHtml(HttpContextBase httpContext, string salt, string domain, string path) {
if (httpContext == null) {
throw new ArgumentNullException("httpContext");
}
return _worker.GetHtml(httpContext, salt, domain, path);
}
示例12: CheckSSLConfig
private void CheckSSLConfig(HttpContextBase httpContext)
{
if (this._config.RequireSSL && !httpContext.Request.IsSecureConnection)
{
throw new InvalidOperationException(WebPageResources.AntiForgeryWorker_RequireSSL);
}
}
示例13: 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());
}
示例14: 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);
}
}
示例15: GetHttpHandler
private static IHttpHandler GetHttpHandler(HttpContextBase context)
{
StubHttpHandler handler = new StubHttpHandler();
handler.ProcessRequestInternal(context);
return handler.Handler;
}