本文整理汇总了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 );
}
}
示例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: 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;
}
示例4: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
using (XmlWriter writer = XmlWriter.Create(response.OutputStream))
{
_feed.SaveAsRss20(writer);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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));
}
示例12: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
using (XmlWriter writer = XmlWriter.Create(response.OutputStream))
{
_Feed.GetRss20Formatter().WriteTo(writer);
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
}