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

C# Web.HttpContextBase类代码示例

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

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



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

示例1: GetRouteDescriptorKey

        public string GetRouteDescriptorKey(HttpContextBase httpContext, RouteBase routeBase) {
            var route = routeBase as Route;
            var dataTokens = new RouteValueDictionary();

            if (route != null) {
                dataTokens = route.DataTokens;
            }
            else {
            var routeData = routeBase.GetRouteData(httpContext);

                if (routeData != null) {
                    dataTokens = routeData.DataTokens;
                }
            }

            var keyBuilder = new StringBuilder();

            if (route != null) {
                keyBuilder.AppendFormat("url={0};", route.Url);
            }

            // the data tokens are used in case the same url is used by several features, like *{path} (Rewrite Rules and Home Page Provider)
            if (dataTokens != null) {
                foreach (var key in dataTokens.Keys) {
                    keyBuilder.AppendFormat("{0}={1};", key, dataTokens[key]);
                }
            }

            return keyBuilder.ToString().ToLowerInvariant();
        }
开发者ID:mikmakcar,项目名称:orchard_fork_learning,代码行数:30,代码来源:CacheService.cs


示例2: Context

        protected override void Context()
        {
            AccountService = MockRepository.GenerateStub<IAccountService>();

            Identity = new FakeIdentity(Username);
            _user = new FakePrincipal(Identity, null);

            HttpRequest = MockRepository.GenerateStub<HttpRequestBase>();
            HttpContext = MockRepository.GenerateStub<HttpContextBase>();
            HttpContext.Stub(x => x.Request).Return(HttpRequest);
            HttpContext.User = _user;

            _httpResponse = MockRepository.GenerateStub<HttpResponseBase>();
            _httpResponse.Stub(x => x.Cookies).Return(new HttpCookieCollection());
            HttpContext.Stub(x => x.Response).Return(_httpResponse);

            Logger = MockRepository.GenerateStub<ILogger>();
            WebAuthenticationService = MockRepository.GenerateStub<IWebAuthenticationService>();

            MappingEngine = MockRepository.GenerateStub<IMappingEngine>();
            AccountCreator = MockRepository.GenerateStub<IAccountCreator>();

            AccountController = new AccountController(AccountService, Logger, WebAuthenticationService, MappingEngine, null, AccountCreator);
            AccountController.ControllerContext = new ControllerContext(HttpContext, new RouteData(), AccountController);
        }
开发者ID:AcklenAvenue,项目名称:PRTools,代码行数:25,代码来源:given_an_account_controller_context.cs


示例3: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            User user = (User)httpContext.Session[WebConstants.UserSessionKey];
      
            if (user == null)
            {
                httpContext.Response.Redirect("~/Account/login");
                return false;
            }
            else
            {
                if (user.Code == "su")
                {
                    return true;
                }
                if (string.IsNullOrWhiteSpace(Permissions))
                {
                    return true;
                }
                else
                {
                    string[] permissionArray = Permissions.Split(AuthorizeAttributeSplitSymbol);
                    foreach (string permission in permissionArray)
                    {
                        if (user.UrlPermissions.Contains(permission))
                        {
                            return true;
                        }
                    }

                    return false;
                }
            }
        }
开发者ID:zhsh1241,项目名称:Sconit5_Shenya,代码行数:34,代码来源:SconitAuthorizeAttribute.cs


示例4: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool isAdmin = false;
            var isAuthorized = base.AuthorizeCore(httpContext);
            if (!isAuthorized)
            {
                // the user is either not authenticated or
                // not in roles => no need to continue any further
                return false;
            }

            // get the currently logged on user
            var username = httpContext.User.Identity.Name;

            // get the id of the article that he is trying to manipulate
            // from the route data (this assumes that the id is passed as a route
            // data parameter: /foo/edit/123). If this is not the case and you
            // are using query string parameters you could fetch the id using the Request
            //var id = httpContext.Request.RequestContext.RouteData.Values["id"] as string;

            // Now that we have the current user and the id of the article he
            // is trying to manipualte all that's left is go ahead and look in
            // our database to see if this user is the owner of the article
            HLGranite.Mvc.Models.hlgraniteEntities db = new HLGranite.Mvc.Models.hlgraniteEntities();
            HLGranite.Mvc.Models.User user = db.Users.Where(u => u.UserName.Equals(username)).FirstOrDefault();
            if (user != null) isAdmin = user.IsAdmin;

            return isAdmin;
        }
开发者ID:hlgranite,项目名称:crm,代码行数:29,代码来源:AuthorizeAdmin.cs


示例5: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!base.AuthorizeCore(httpContext))
                return false;

            return Permission.IsEmptyOrNull() || Authorization.HasPermission(Permission);
        }
开发者ID:CodeFork,项目名称:Serenity,代码行数:7,代码来源:PageAuthorizeAttribute.cs


示例6: WebWorkContext

 public WebWorkContext(HttpContextBase httpContext,
     ICustomerService customerService,
     IVendorService vendorService,
     IStoreContext storeContext,
     IAuthenticationService authenticationService,
     ILanguageService languageService,
     ICurrencyService currencyService,
     IGenericAttributeService genericAttributeService,
     TaxSettings taxSettings, 
     CurrencySettings currencySettings,
     LocalizationSettings localizationSettings,
     IUserAgentHelper userAgentHelper,
     IStoreMappingService storeMappingService)
 {
     this._httpContext = httpContext;
     this._customerService = customerService;
     this._vendorService = vendorService;
     this._storeContext = storeContext;
     this._authenticationService = authenticationService;
     this._languageService = languageService;
     this._currencyService = currencyService;
     this._genericAttributeService = genericAttributeService;
     this._taxSettings = taxSettings;
     this._currencySettings = currencySettings;
     this._localizationSettings = localizationSettings;
     this._userAgentHelper = userAgentHelper;
     this._storeMappingService = storeMappingService;
 }
开发者ID:HumanSystems,项目名称:nopcommerce-dev,代码行数:28,代码来源:WebWorkContext.cs


示例7: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (!httpContext.User.Identity.IsAuthenticated)
                return false;

            return httpContext.User.IsInRole(Roles);
        }
开发者ID:pampero,项目名称:hopeOnline,代码行数:7,代码来源:AuthorizeUser.cs


示例8: GetViewLocation

        public string GetViewLocation(HttpContextBase httpContext, string key) {
            if (httpContext == null) {
                throw new ArgumentNullException("httpContext");
            }

            return (string)httpContext.Cache[AlterKey(key)];
        }
开发者ID:wolfweb,项目名称:Ww,代码行数:7,代码来源:ThemeViewLocationCache.cs


示例9: GetRouteData

        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            // locate appropriate shell settings for request
            var settings = _runningShellTable.Match(httpContext);

            // only proceed if there was a match, and it was for this client
            if (settings == null || settings.Name != _shellSettings.Name)
                return null;

            var effectiveHttpContext = httpContext;
            if (_urlPrefix != null)
                effectiveHttpContext = new UrlPrefixAdjustedHttpContext(httpContext, _urlPrefix);

            var routeData = _route.GetRouteData(effectiveHttpContext);
            if (routeData == null)
                return null;

            // otherwise wrap handler and return it
            routeData.RouteHandler = new RouteHandler(_workContextAccessor, routeData.RouteHandler, SessionState);
            routeData.DataTokens["IWorkContextAccessor"] = _workContextAccessor;

            if (IsHttpRoute) {
                routeData.Values["IWorkContextAccessor"] = _workContextAccessor; // for WebApi
            }

            return routeData;
        }
开发者ID:ZhenghaiYe,项目名称:OrchardNoCMS,代码行数:27,代码来源:ShellRoute.cs


示例10: Match

 public bool Match(HttpContextBase httpContext, Route route, string parameterName, 
     RouteValueDictionary values, RouteDirection routeDirection)
 {
     Debug.WriteLine(httpContext.Request.HttpMethod == "GET");
     return httpContext.Request.UserAgent != null &&
         httpContext.Request.UserAgent.Contains(requiredUserAgent);
 }
开发者ID:NikolayKostadinov,项目名称:ASP.Net-MVC5,代码行数:7,代码来源:UserAgentConstraint.cs


示例11: GetCurrentPage

 /// <summary>
 /// Gets current page.
 /// </summary>
 /// <returns>Current page object.</returns>
 public IPage GetCurrentPage(HttpContextBase httpContext)
 {
     // TODO: remove it or optimize it.
     var http = new HttpContextTool(httpContext);
     var virtualPath = HttpUtility.UrlDecode(http.GetAbsolutePath());
     return GetPageByVirtualPath(virtualPath) ?? new Page(); // TODO: do not return empty page, should implemented another logic.
 }
开发者ID:navid60,项目名称:BetterCMS,代码行数:11,代码来源:DefaultPageService.cs


示例12: Handle

		public virtual void Handle(HttpContextBase context)
		{
            string action = context.Request["action"];				
			try
			{
				if (!Handlers.ContainsKey(action))
					throw new InvalidOperationException("Couln't find any handler for the action: " + action);

				IAjaxService service = Handlers[action];

				if (service.RequiresEditAccess && !security.IsEditor(context.User))
					throw new PermissionDeniedException(null, context.User);

				if (!service.IsValidHttpMethod(context.Request.HttpMethod))
					throw new HttpException((int)HttpStatusCode.MethodNotAllowed, "This service requires HTTP POST method");

				service.Handle(context);
			}
			catch (Exception ex)
			{
                Logger.ErrorFormat("AJAX {0}: {1}", action, ex.Message);
				context.Response.Status = ((int)HttpStatusCode.InternalServerError).ToString() + " Internal Server Error";
				context.Response.Write(WriteException(ex, context.User));
			}
		}
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:25,代码来源:AjaxRequestDispatcher.cs


示例13: AuthorizeCore

 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     try
     {
         string url = httpContext.Request.Path;
         url = url.Substring(0, url.IndexOf("?") > 1 ? url.IndexOf("?") : url.Length);
         HttpCookie authcookie = httpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
         if (authcookie == null)
         {
             string token = httpContext.Request.Form["token"].ToString();
             XXF.BasicService.CertCenter.CertCenterProvider ccp = new XXF.BasicService.CertCenter.CertCenterProvider(XXF.BasicService.CertCenter.ServiceCertType.manage);
             if (ccp.Auth(token))
             {
                 return true;
             }
             return false;
         }
         try
         {
             FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authcookie.Value);
             string userid = ticket.Name.Split(' ').FirstOrDefault();
             return true;
         }
         catch
         {
             return false;
         }
     }
     catch
     {
         return false;
     }
 }
开发者ID:houzhenggang,项目名称:Dyd.BaseService.TaskManager,代码行数:33,代码来源:AuthorityCheck.cs


示例14: ProcessSignInResponse

        public override ClaimsIdentity ProcessSignInResponse(string realm, string originalUrl, HttpContextBase httpContext)
        {
            var client = new FacebookClient(this.applicationId, this.secret);

            AuthenticationResult result;
            try
            {
                result = client.VerifyAuthentication(httpContext, this.MultiProtocolIssuer.ReplyUrl);
            }
            catch (WebException wex)
            {
                throw new InvalidOperationException(new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(), wex);
            }

            var claims = new List<Claim>
                {
                    new Claim(System.IdentityModel.Claims.ClaimTypes.NameIdentifier, result.ExtraData["id"])
                };

            foreach (var claim in result.ExtraData)
            {
                claims.Add(new Claim("http://schemas.facebook.com/me/" + claim.Key, claim.Value));
            }

            return new ClaimsIdentity(claims, "Facebook");
        }
开发者ID:Teleopti,项目名称:authbridge,代码行数:26,代码来源:FacebookHandler.cs


示例15: Process

        public ActionResult Process(HttpContextBase context, AuthenticateCallbackData model)
        {
            if (model.Exception != null)
                throw model.Exception;

            var client = model.AuthenticatedClient;
            var username = client.UserInformation.UserName;

            FormsAuthentication.SetAuthCookie(username, false);

            context.Response.AppendCookie(new HttpCookie("AccessToken", client.AccessToken.SecretToken)
            {
                Secure = !context.IsDebuggingEnabled,
                HttpOnly = true
            });

            var urlHelper = new UrlHelper(((MvcHandler)context.Handler).RequestContext);
            var redirectUrl = string.Format("/{0}/", username);
            var cookie = context.Request.Cookies["returnUrl"];
            if (cookie != null && urlHelper.IsLocalUrl(cookie.Value))
            {
                redirectUrl = cookie.Value;
                cookie.Expires = DateTime.Now.AddDays(-1);
                context.Response.Cookies.Add(cookie);
            }

            return new RedirectResult(redirectUrl);
        }
开发者ID:nikmd23,项目名称:signatory,代码行数:28,代码来源:AuthenticationCallbackController.cs


示例16: RenderJsDependencies

        protected override string RenderJsDependencies(IEnumerable<IClientDependencyFile> jsDependencies, HttpContextBase http, IDictionary<string, string> htmlAttributes)
        {
            if (!jsDependencies.Any())
                return string.Empty;

            var sb = new StringBuilder();
            
            if (http.IsDebuggingEnabled || !EnableCompositeFiles)
            {
                foreach (var dependency in jsDependencies)
                {
                    sb.Append(RenderSingleJsFile(dependency.FilePath, htmlAttributes));
                }
            }
            else
            {
                var comp = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.ProcessCompositeList(jsDependencies, ClientDependencyType.Javascript, http);
                foreach (var s in comp)
                {
                    sb.Append(RenderSingleJsFile(s, htmlAttributes));
                }
            }

            return sb.ToString();
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:25,代码来源:DnnFormBottomRenderProvider.cs


示例17: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool authorized = false;

            if (httpContext.Session["username"] != null)
            {
                if (Roles.ToString() != "")
                {
                    if (httpContext.Session["Role"].ToString().Equals("Super Admin") ||
                        httpContext.Session["Role"].ToString().Equals("Manager")) authorized = true;
                    else
                    {
                        authorized = false;
                    }
                }
                else
                {
                    authorized = true;
                }
            }
            if (!authorized)
            {
                // The user is not authorized => no need to go any further
                return false;
            }

            return true;
        }
开发者ID:mariotj,项目名称:prototipeSIL,代码行数:28,代码来源:MyAuthorizeAttribute.cs


示例18: 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:bunsen32,项目名称:typed-url-routing,代码行数:32,代码来源:PathHelpers.cs


示例19: InsertViewLocation

        public void InsertViewLocation(HttpContextBase httpContext, string key, string virtualPath) {
            if (httpContext == null) {
                throw new ArgumentNullException("httpContext");
            }

            httpContext.Cache.Insert(AlterKey(key), virtualPath, new CacheDependency(HostingEnvironment.MapPath("~/Themes")));
        }
开发者ID:wolfweb,项目名称:Ww,代码行数:7,代码来源:ThemeViewLocationCache.cs


示例20: GetInstances

        internal static IDictionary<UnityPerWebRequestLifetimeManager, object> GetInstances(HttpContextBase httpContext)
        {
            IDictionary<UnityPerWebRequestLifetimeManager, object> instances;

            if (httpContext.Items.Contains(Key))
            {
                instances = (IDictionary<UnityPerWebRequestLifetimeManager, object>)httpContext.Items[Key];
            }
            else
            {
                lock (httpContext.Items)
                {
                    if (httpContext.Items.Contains(Key))
                    {
                        instances = (IDictionary<UnityPerWebRequestLifetimeManager, object>)httpContext.Items[Key];
                    }
                    else
                    {
                        instances = new Dictionary<UnityPerWebRequestLifetimeManager, object>();
                        httpContext.Items.Add(Key, instances);
                    }
                }
            }

            return instances;
        }
开发者ID:medvekoma,项目名称:portfotolio,代码行数:26,代码来源:UnityPerWebRequestLifetimeModule.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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