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


C# Web.HttpContextBase类代码示例

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


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


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