當前位置: 首頁>>代碼示例>>C#>>正文


C# Web.HttpResponseBase類代碼示例

本文整理匯總了C#中System.Web.HttpResponseBase的典型用法代碼示例。如果您正苦於以下問題:C# HttpResponseBase類的具體用法?C# HttpResponseBase怎麽用?C# HttpResponseBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpResponseBase類屬於System.Web命名空間,在下文中一共展示了HttpResponseBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetResponse

		/// <summary>
		/// set http response cookies
		/// </summary>
		/// <param name="response"></param>
		/// <param name="companyUserSesson">if null-remove cookie</param>
		public void SetResponse ( HttpResponseBase response , CompanyUserSession companyUserSesson )
		{
			if (companyUserSesson != null)
			{

				if (response.Cookies[SessionIdCookieName] == null)
				{
					HttpCookie sidCookie = new HttpCookie(SessionIdCookieName, companyUserSesson.Sid);
					response.Cookies.Add(sidCookie);
				}
				else
				{
					response.Cookies[SessionIdCookieName].Value = companyUserSesson.Sid;
				}
				if (response.Cookies[UserIdCookieName] == null)
				{
					HttpCookie uIdCookie = new HttpCookie(UserIdCookieName, companyUserSesson.CompanyUserId.ToString());
					response.Cookies.Add(uIdCookie);
				}
				else
				{
					response.Cookies[UserIdCookieName].Value = companyUserSesson.CompanyUserId.ToString();
				}
			}
			else
			{
				HttpCookie uIdCookie = new HttpCookie(UserIdCookieName, "") {Expires = DateTime.Now};
				response.Cookies.Add ( uIdCookie );
				HttpCookie sidCookie = new HttpCookie(SessionIdCookieName, "") {Expires = DateTime.Now};
				response.Cookies.Add ( sidCookie );
			}
		}
開發者ID:alexey-aristov,項目名稱:Advertising,代碼行數:37,代碼來源:AuthProvider.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: HandleResult

        public bool HandleResult( IResult result, IFormatInfo outputFormat, HttpRequestBase request, HttpResponseBase response )
        {
            response.AddHeader("Accept-Ranges", "bytes");

            Range range;
            if ( !TryGetRequestedRange( request, out range ) )
            {
                return false;
            }

            if (!ValidateIfRangeHeader(request, result))
            {
                return false;
            }

            var offset = range.Start ?? 0;
            var end = range.End.HasValue ? range.End.Value : result.ContentLength - 1;
            var length = end - offset + 1;

            response.AddHeader( "Content-Range", "bytes " + offset + "-" + end + "/" + result.ContentLength );
            response.StatusCode = 206;

            result.Serve( response, offset, length );
            return true;
        }
開發者ID:bmbsqd,項目名稱:dynamic-media,代碼行數:25,代碼來源:BytesRangeResultHandler.cs

示例4: WriteFile

 protected override void WriteFile(HttpResponseBase response)
 {
     using (XmlWriter writer = XmlWriter.Create(response.OutputStream))
     {
         _feed.SaveAsRss20(writer);
     }
 }
開發者ID:inatoff,項目名稱:ACTS_Site,代碼行數:7,代碼來源:RssResult.cs

示例5: SerializeData

        protected virtual void SerializeData(HttpResponseBase response)
        {
            if (ErrorMessages.Any())
            {
                var originalData = Data;
                Data = new
                {
                    Success = false,
                    OriginalData = originalData,
                    ErrorMessage = string.Join("\n", ErrorMessages),
                    ErrorMessages = ErrorMessages.ToArray()
                };

                response.StatusCode = StatusCode;
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters = new JsonConverter[]
                {
                    new StringEnumConverter(),
                },
            };

            response.Write(JsonConvert.SerializeObject(Data, settings));
        }
開發者ID:andrewreyes,項目名稱:NiftyMvcHelpers,代碼行數:27,代碼來源:StandardJsonResult.cs

示例6: PrepareExcel

        /// <summary>
        /// Prepares the excel.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        /// <param name="reportName">Name of the report.</param>
        /// <param name="reportTitle">The report title.</param>
        /// <param name="responseBase">The response base.</param>
        /// <param name="serverBase">The server base.</param>
        public void PrepareExcel(DataTable dataTable, string reportName, string reportTitle, HttpResponseBase responseBase, HttpServerUtilityBase serverBase)
        {
            this.response = responseBase;
            this.server = serverBase;

            this.GenerateTable(dataTable, reportName, reportTitle);
        }
開發者ID:JaipurAnkita,項目名稱:mastercode,代碼行數:15,代碼來源:ExcelProvider.cs

示例7: CacheLongTime

 void CacheLongTime(HttpResponseBase response, string actualETag)
 {
     response.Cache.SetCacheability(HttpCacheability.Public);
     response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
     response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
     response.Cache.SetETag(actualETag);
 }
開發者ID:justanswer,項目名稱:cassette,代碼行數:7,代碼來源:AssetRequestHandler.cs

示例8: FillResponse

 public void FillResponse(HttpResponseBase response, HttpContextBase context)
 {
     var trigger = context.Request.Params["trigger"];
     var jobGroup = context.Request.Params["group"];
     _schedulerProvider.Scheduler.PauseTrigger(trigger, jobGroup);
     response.Redirect(context.Request.UrlReferrer.OriginalString);
 }
開發者ID:JustAGhosT,項目名稱:CrystalQuartz,代碼行數:7,代碼來源:PauseTriggerFiller.cs

示例9: DoAction

        protected override void DoAction(HttpResponseBase response, HttpContextBase context)
        {
            var jobName = context.Request.Params["job"];
            var jobGroup = context.Request.Params["group"];

            _schedulerProvider.Scheduler.PauseJob(new JobKey(jobName, jobGroup));
        }
開發者ID:serbrech,項目名稱:CrystalQuartz,代碼行數:7,代碼來源:PauseJobFiller.cs

示例10: GetFavs

        public static Dictionary<string, string> GetFavs(HttpResponseBase Response)
        {
            Dictionary<string, string> favs = new Dictionary<string, string>();
            HttpCookie testCookie = new HttpCookie("favorites");
            testCookie.Expires = DateTime.Now.AddHours(24);
            testCookie.Name = "favorites";
            testCookie.Values.Add("linkText", "linkUrl");
            testCookie.Values.Add("linkText2", "linkUrl2");
            Response.Cookies.Add(testCookie);

            System.Web.HttpCookie cookieFavs = Response.Cookies.Get("favorites");

            if (cookieFavs.Values.Count > 0)
            {
                NameValueCollection nvc = cookieFavs.Values;
                for (int i = 0; i < nvc.Count; i++ )
                {
                    string key = nvc.Keys[i];
                    string value = nvc[i];
                    favs.Add(Resources.Localizer.GetString("Resources.Shared.Nav", key, key), value);
                }
            }
            else // get from db
            {

            }

            return favs;
        }
開發者ID:ManEx,項目名稱:WebManex,代碼行數:29,代碼來源:Favorites.cs

示例11: DoAction

        protected override void DoAction(HttpResponseBase response, HttpContextBase context)
        {
            var trigger = context.Request.Params["trigger"];
            var jobGroup = context.Request.Params["group"];

            _schedulerProvider.Scheduler.ResumeTrigger(new TriggerKey(trigger, jobGroup));
        }
開發者ID:JustAGhosT,項目名稱:CrystalQuartz,代碼行數:7,代碼來源:ResumeTriggerFiller.cs

示例12: WriteFile

 protected override void WriteFile(HttpResponseBase response)
 {
     using (XmlWriter writer = XmlWriter.Create(response.OutputStream))
     {
         _Feed.GetRss20Formatter().WriteTo(writer);
     }
 }
開發者ID:okfurs,項目名稱:okfurs.com,代碼行數:7,代碼來源:RssResult.cs

示例13: XrcResponse

        public XrcResponse(Stream stream, HttpResponseBase parentResponse = null)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            _innerResponse = parentResponse;

            _isStreamOwner = true;
            if (_innerResponse == null)
            {
                _cookies = new HttpCookieCollection();
                _statusCode = (int)HttpStatusCode.OK;
                _contentEncoding = Encoding.UTF8;
                _contentType = "text/html; charset=UTF-8";
                _redirectLocation = null;
                _statusDescription = null;
                _outputStream = stream;
                _output = new StreamWriter(stream, _contentEncoding);
            }
            else
            {
                _cookies = _innerResponse.Cookies;
                _statusCode = (int)HttpStatusCode.OK;
                _contentEncoding = _innerResponse.ContentEncoding;
                _contentType = _innerResponse.ContentType;
                _redirectLocation = null;
                _statusDescription = null;
                _outputStream = stream;
                _output = new StreamWriter(stream, _contentEncoding);
            }
        }
開發者ID:davideicardi,項目名稱:xrc,代碼行數:31,代碼來源:XrcResponse.cs

示例14: ChooseSuitableCompression

        public static void ChooseSuitableCompression(NameValueCollection requestHeaders, HttpResponseBase response)
        {
            if (requestHeaders == null) throw new ArgumentNullException(nameof(requestHeaders));
            if (response == null) throw new ArgumentNullException(nameof(response));


            /// load encodings from header
            QValueList encodings = new QValueList(requestHeaders[ACCEPT_ENCODING_HEADER]);

            /// get the types we can handle, can be accepted and
            /// in the defined client preference
            QValue preferred = encodings.FindPreferred("gzip", "deflate", "identity");

            /// if none of the preferred values were found, but the
            /// client can accept wildcard encodings, we'll default
            /// to Gzip.
            if (preferred.IsEmpty && encodings.AcceptWildcard && encodings.Find("gzip").IsEmpty)
                preferred = new QValue("gzip");

            // handle the preferred encoding
            switch (preferred.Name)
            {
                case "gzip":
                    response.AppendHeader(CONTENT_ENCODING_HEADER, "gzip");
                    response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                    break;
                case "deflate":
                    response.AppendHeader(CONTENT_ENCODING_HEADER, "deflate");
                    response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                    break;
                case "identity":
                default:
                    break;
            }
        }
開發者ID:Geta,項目名稱:SEO.Sitemaps,代碼行數:35,代碼來源:CompressionHandler.cs

示例15: Restore

		public static void Restore(HttpRequestBase request, HttpResponseBase response)
		{
			string serverHash = request.QueryString[queryStringName];

			if (serverHash != null)
			{
				string cookieHeader = request.Headers["Cookie"];
				string cookieValue = cookieName + "=" + serverHash;

				// Modifying request.Cookies doesn't work

				if (cookieHeader != null)
				{
					if (cookieHeader.Contains(cookieName + "="))
					{
						cookieHeader = regex.Replace(cookieHeader, cookieValue + ";");
					}
					else
					{
						cookieHeader += "; " + cookieValue;
					}

					request.Headers["Cookie"] = cookieHeader;
				}
				else
				{
					request.Headers.Add("Cookie", cookieValue);
				}

				// response.Cookies also updates request.Cookies, which may have other implications, so we set the raw cookie
				response.Headers.Add("Set-Cookie", cookieName + "=" + serverHash + ";Path=" + request.ApplicationPath + ";Domain=" + request.Url.Host);
			}
		}
開發者ID:envoyat,項目名稱:Envoy.ArrCookieRestorer,代碼行數:33,代碼來源:ArrCookieRestorerModule.cs


注:本文中的System.Web.HttpResponseBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。