• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# HttpContextBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中HttpContextBase的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase类的具体用法?C# HttpContextBase怎么用?C# HttpContextBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpContextBase类属于命名空间,在下文中一共展示了HttpContextBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: FormsAuthenticationHelper

 /// <summary>
 /// 使用当前Http请求的上下文信息初始化 FormsAuthenticationHelper 类的新实例
 /// </summary>
 /// <param name="context"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public FormsAuthenticationHelper(HttpContextBase context)
 {
     if (context == null)
         throw new ArgumentNullException("context");
     this._Context = context;
     UserIdentity = context.User == null ? null : context.User.Identity as FormsIdentity;
 }
开发者ID:shalves,项目名称:CompactMVC,代码行数:12,代码来源:FormsAuthenticationHelper.cs


示例17: AuthorizeCore

        // This method must be thread-safe since it is called by the thread-safe OnCacheAuthorization() method.
        protected virtual bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            IPrincipal user = httpContext.User;
            if (!user.Identity.IsAuthenticated)
            {
                return false;
            }

            if (_usersSplit.Length > 0 && !_usersSplit.Contains(user.Identity.Name, StringComparer.OrdinalIgnoreCase))
            {
                return false;
            }

            if (_rolesSplit.Length > 0 && !_rolesSplit.Any(user.IsInRole))
            {
                return false;
            }

            return true;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:26,代码来源:AuthorizeAttribute.cs


示例18: GetRouteData

 public override RouteData GetRouteData(HttpContextBase httpContext)
 {
     try
     {
         if (HttpRoute is HostedHttpRoute)
         {
             return base.GetRouteData(httpContext);
         }
         else
         {
             // if user passed us a custom IHttpRoute, then we should invoke their function instead of the base
             HttpRequestMessage request = httpContext.GetOrCreateHttpRequestMessage();
             IHttpRouteData data = HttpRoute.GetRouteData(httpContext.Request.ApplicationPath, request);
             return data == null ? null : data.ToRouteData();
         }
     }
     catch (HttpResponseException e)
     {
         // Task.Wait is fine here as ConvertResponse calls into MediaTypeFormatter.WriteToStreamAsync which happens
         // synchronously in the default case (our default formatters are synchronous).
         HttpControllerHandler.ConvertResponse(httpContext, e.Response, httpContext.GetOrCreateHttpRequestMessage()).Wait();
         httpContext.Response.End();
         return null;
     }
 }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:25,代码来源:HttpWebRoute.cs


示例19: GenerateClientUrlInternal

        private static string GenerateClientUrlInternal(HttpContextBase httpContext, string contentPath)
        {
            if (String.IsNullOrEmpty(contentPath))
            {
                return contentPath;
            }

            // can't call VirtualPathUtility.IsAppRelative since it throws on some inputs
            bool isAppRelative = contentPath[0] == '~';
            if (isAppRelative)
            {
                string absoluteContentPath = VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);
                string modifiedAbsoluteContentPath = httpContext.Response.ApplyAppPathModifier(absoluteContentPath);
                return GenerateClientUrlInternal(httpContext, modifiedAbsoluteContentPath);
            }

            // we only want to manipulate the path if URL rewriting is active for this request, else we risk breaking the generated URL
            bool wasRequestRewritten = _urlRewriterHelper.WasRequestRewritten(httpContext);
            if (!wasRequestRewritten)
            {
                return contentPath;
            }

            // Since the rawUrl represents what the user sees in his browser, it is what we want to use as the base
            // of our absolute paths. For example, consider mysite.example.com/foo, which is internally
            // rewritten to content.example.com/mysite/foo. When we want to generate a link to ~/bar, we want to
            // base it from / instead of /foo, otherwise the user ends up seeing mysite.example.com/foo/bar,
            // which is incorrect.
            string relativeUrlToDestination = MakeRelative(httpContext.Request.Path, contentPath);
            string absoluteUrlToDestination = MakeAbsolute(httpContext.Request.RawUrl, relativeUrlToDestination);
            return absoluteUrlToDestination;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:32,代码来源:PathHelpers.cs


示例20: VerifyAndProcessRequest

        protected override void VerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext) {
            if (httpHandler == null) {
                throw new ArgumentNullException("httpHandler");
            }

            httpHandler.ProcessRequest(HttpContext.Current);
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:MvcHttpHandler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# HttpControllerDescriptor类代码示例发布时间:2022-05-24
下一篇:
C# HttpContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap