本文整理汇总了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();
}
示例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);
}
示例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;
}
}
}
示例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;
}
示例5: AuthorizeCore
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (!base.AuthorizeCore(httpContext))
return false;
return Permission.IsEmptyOrNull() || Authorization.HasPermission(Permission);
}
示例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;
}
示例7: AuthorizeCore
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (!httpContext.User.Identity.IsAuthenticated)
return false;
return httpContext.User.IsInRole(Roles);
}
示例8: GetViewLocation
public string GetViewLocation(HttpContextBase httpContext, string key) {
if (httpContext == null) {
throw new ArgumentNullException("httpContext");
}
return (string)httpContext.Cache[AlterKey(key)];
}
示例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;
}
示例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);
}
示例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.
}
示例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));
}
}
示例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;
}
}
示例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");
}
示例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);
}