当前位置: 首页>>代码示例>>C#>>正文


C# HttpContextBase类代码示例

本文整理汇总了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);
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:30,代码来源:MvcHttpHandler.cs

示例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));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:25,代码来源:MetaTableHelper.cs

示例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;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:29,代码来源:LengthRouteConstraint.cs

示例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);
                    }
                }
            }
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:31,代码来源:WebPageRoute.cs

示例5: AddVersionHeader

 /// <summary>
 /// 在响应头中设置MVC版本信息
 /// </summary>
 /// <param name="httpContext"></param>
 protected internal virtual void AddVersionHeader(HttpContextBase httpContext)
 {
     if (!DisableMvcResponseHeader)
     {
         httpContext.Response.AppendHeader(MvcVersionHeaderName, MvcVersion);
     }
 }
开发者ID:mstmdev,项目名称:Mstm.aspnetwebstack,代码行数:11,代码来源:MvcHandler.cs

示例6: Validate

 protected virtual bool Validate(HttpContextBase context)
 {
     if(context.User == null || context.User.Identity == null)
         return false;
     
     return context.User.Identity.IsAuthenticated;
 }
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:7,代码来源:RequireAuthorizationAttribute.cs

示例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);
                }
            });
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:60,代码来源:MvcHandler.cs

示例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;
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:30,代码来源:CultureUtil.cs

示例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;
     }
 }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:7,代码来源:CultureUtil.cs

示例10: Validate

        public static void Validate(HttpContextBase httpContext, string salt) {
            if (httpContext == null) {
                throw new ArgumentNullException("httpContext");
            }

            _worker.Validate(httpContext, salt);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:7,代码来源:AntiForgery.cs

示例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);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:7,代码来源:AntiForgery.cs

示例12: CheckSSLConfig

		private void CheckSSLConfig(HttpContextBase httpContext)
		{
			if (this._config.RequireSSL && !httpContext.Request.IsSecureConnection)
			{
				throw new InvalidOperationException(WebPageResources.AntiForgeryWorker_RequireSSL);
			}
		}
开发者ID:BikS2013,项目名称:bUtility,代码行数:7,代码来源:AntiForgeryWorker.cs

示例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());
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:7,代码来源:MvcHttpHandler.cs

示例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);
            }
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:32,代码来源:SessionStateUtil.cs

示例15: GetHttpHandler

		private static IHttpHandler GetHttpHandler(HttpContextBase context)
		{
			StubHttpHandler handler = new StubHttpHandler();
			handler.ProcessRequestInternal(context);

			return handler.Handler;
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:7,代码来源:MvcHttpAsyncHandler.cs


注:本文中的HttpContextBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。