本文整理匯總了C#中System.Web.HttpResponseBase.Write方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpResponseBase.Write方法的具體用法?C# HttpResponseBase.Write怎麽用?C# HttpResponseBase.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.Write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Execute
public virtual void Execute(HttpResponseBase response)
{
if (_isAutomatedTool)
{
var console = new UnicornStringConsole();
ProcessInternal(console);
response.ContentType = "text/plain";
response.Write(_title + "\n\n");
response.Write(console.Output);
if (console.HasErrors)
{
response.StatusCode = 500;
response.TrySkipIisCustomErrors = true;
}
response.End();
}
else
{
var console = new CustomStyledHtml5WebConsole(response);
console.Title = _title;
console.Render(ProcessInternal);
}
}
示例2: SaveSectionToDb
private static void SaveSectionToDb(List<string> section, int section_id, HttpResponseBase response)
{
string url = String.Empty;
int ch_count = 1;
int current_ch = 1;
XDocument xml = null;
int chapter_id = 0;
int book_id = 0;
foreach (string abbrev in section)
{
response.Write("<br /><hr /><br />");
while(current_ch <= ch_count)
{
using(var db = new Entities())
{
url = "http://piibel.net/.xml?q=" + abbrev + "%20" + current_ch;
xml = XDocument.Load(url);
if(current_ch == 1)
{
book_id = AddBook(section_id, xml);
ch_count = Int32.Parse(xml.Descendants("bible").First().Attribute("pages").Value);
}
chapter_id = AddChapter(xml, book_id);
AddVerses(xml, chapter_id);
response.Write("Saved: " + abbrev + " " + current_ch + "<br />");
response.Flush();
current_ch++;
}
}
current_ch = 1;
ch_count = 1;
}
}
示例3: ResponseImg
private void ResponseImg(HttpResponseBase response, string pic)
{
try
{
string FilePath = AppDomain.CurrentDomain.BaseDirectory;
FilePath = Path.Combine(FilePath, "App_Data\\" + imgpath);
string FileFullPath = Path.Combine(FilePath, pic);
string FileExt = Path.GetExtension(FileFullPath);
if (U.ExtValid(FileExt))
{
if (File.Exists(FileFullPath))
{
FileExt = FileExt.ToLower();
Image Img = Image.FromFile(FileFullPath);
ImageFormat format = ImageFormat.Jpeg;
switch (FileExt)
{
case ".gif":
format = ImageFormat.Gif;
break;
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".png":
format = ImageFormat.Png;
break;
default:
break;
}
response.ClearContent();
response.ContentType = "image/bmp";
Img.Save(response.OutputStream, format);
Img.Dispose();
response.Flush();
}
else
{
response.Write("file DO NOT Exists");
}
}
else
{
response.Write("file DO NOT Allow");
}
}
catch (Exception ex)
{
log.Warn(ex.Message);
log.Warn("imgpath:{0},imgname:{1}", imgpath, imgname);
}
}
示例4: Apply
public void Apply(HttpResponseBase response)
{
if(response == null)
{
throw new ArgumentNullException("response");
}
response.Cache.SetCacheability(Cacheability);
if (HttpStatusCode == HttpStatusCode.SeeOther || Location != null)
{
if (Location == null)
{
throw new InvalidOperationException("Missing Location on redirect.");
}
if (HttpStatusCode != HttpStatusCode.SeeOther)
{
throw new InvalidOperationException("Invalid HttpStatusCode for redirect, but Location is specified");
}
response.Redirect(Location.ToString());
}
else
{
response.StatusCode = (int)HttpStatusCode;
response.ContentType = ContentType;
response.Write(Content);
response.End();
}
}
示例5: GetNotifyData
/// <summary>
/// 接收從微信支付後台發送過來的數據並驗證簽名
/// </summary>
/// <returns>微信支付後台返回的數據</returns>
public WxPayData GetNotifyData(HttpResponseBase response, HttpRequestBase request)
{
//接收從微信後台POST過來的數據
System.IO.Stream s = request.InputStream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder();
while ((count = s.Read(buffer, 0, 1024)) > 0)
{
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
}
s.Flush();
s.Close();
s.Dispose();
//轉換數據格式並驗證簽名
WxPayData data = new WxPayData();
try
{
data.FromXml(builder.ToString());
}
catch(WxPayException ex)
{
//若簽名錯誤,則立即返回結果給微信支付後台
WxPayData res = new WxPayData();
res.SetValue("return_code", "FAIL");
res.SetValue("return_msg", ex.Message);
response.Write(res.ToXml());
}
return data;
}
示例6: WriteContent
private void WriteContent(HttpResponseBase response)
{
if (!String.IsNullOrEmpty(ContentType)) {
response.ContentType = ContentType;
} else {
response.ContentType = "application/json";
}
if (ContentEncoding != null) {
response.ContentEncoding = ContentEncoding;
}
if (Data != null) {
if (Data is String) {
// write strings directly to avoid double quotes around them caused by JsonSerializer
response.Write(Data);
} else {
using (JsonWriter writer = new JsonTextWriter(response.Output)) {
JsonSerializer serializer = JsonSerializer.Create(Settings);
var converter = ProviderConfiguration.GetDefaultDateTimeConverter();
if (converter != null) {
serializer.Converters.Add(converter);
}
#if DEBUG
writer.Formatting = Formatting.Indented;
#else
writer.Formatting = ProviderConfiguration.GetConfiguration().Debug ? Formatting.Indented : Formatting.None;
#endif
serializer.Serialize(writer, Data);
}
}
}
}
示例7: 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 = 400;
}
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new JsonConverter[]
{
new StringEnumConverter(),
},
};
response.Write(JsonConvert.SerializeObject(Data, settings));
}
示例8: Apply
public static void Apply(this CommandResult commandResult, HttpResponseBase response)
{
if (commandResult == null)
{
throw new ArgumentNullException(nameof(commandResult));
}
if (response == null)
{
throw new ArgumentNullException(nameof(response));
}
if (commandResult.HttpStatusCode == HttpStatusCode.SeeOther || commandResult.Location != null)
{
if (commandResult.Location == null)
{
throw new InvalidOperationException("Missing Location on redirect.");
}
if (commandResult.HttpStatusCode != HttpStatusCode.SeeOther)
{
throw new InvalidOperationException("Invalid HttpStatusCode for redirect, but Location is specified");
}
response.Redirect(commandResult.Location.OriginalString);
}
else
{
response.StatusCode = (int)commandResult.HttpStatusCode;
response.ContentType = commandResult.ContentType;
response.Write(commandResult.Content);
response.End();
}
}
示例9: CheckForAuthorizationFailure
/// <summary>
/// Checks for authorization failure and if result of ajax call overrides asp.net redirect to return a 401.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="response">The response.</param>
/// <param name="context">The context.</param>
internal void CheckForAuthorizationFailure(HttpRequestBase request, HttpResponseBase response, HttpContextBase context)
{
if (!request.IsAjaxRequest() || !true.Equals(context.Items["RequestWasNotAuthorized"])) return;
response.StatusCode = 401;
response.ClearContent();
var content = new {title = HttpContext.GetGlobalResourceObject("Session", "Title.SessionHasExpired"), content = HttpContext.GetGlobalResourceObject("Session", "Messsage.SessionHasExpired")};
var serializer = new JavaScriptSerializer();
response.Write(serializer.Serialize(content));
}
示例10: SendMessages
public void SendMessages(HttpResponseBase response, IEnumerable<Message> messages)
{
string messageAsJson = MessageConverter.ToJson(messages);
string functionName = callback ?? "jsonpcallback";
string functionCall = string.Format("{0} ( {1} )", functionName, messageAsJson);
response.ContentType = "text/javascript";
response.Write(functionCall);
}
示例11: WriteExcelFile
public static void WriteExcelFile(HttpResponseBase response,string output,string fileName)
{
response.Clear();
response.Buffer = true;
response.Charset = "utf-8";
response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
response.ContentType = "application/ms-excel";
response.Write(output);
}
示例12: ExportCsv
public static void ExportCsv(ExportEventArgs options, HttpResponseBase response)
{
response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.csv", options.Title));
response.ContentType = "application/csv";
if (CultureInfo.CurrentUICulture.Name != "en-US")
{
response.ContentEncoding = Encoding.Unicode;
}
response.Write(options.Document);
}
示例13: Write
public void Write(HttpResponseBase httpResponse, string contentType, Encoding contentEncoding) {
string jsonResponse = ToJson();
if (IsFileUpload) {
const string s = "<html><body><textarea>{0}</textarea></body></html>";
httpResponse.ContentType = "text/html";
httpResponse.Write(String.Format(s, jsonResponse.Replace(""", "\\"")));
} else {
if (!String.IsNullOrEmpty(contentType)) {
httpResponse.ContentType = contentType;
} else {
httpResponse.ContentType = "application/json";
}
if (contentEncoding != null) {
httpResponse.ContentEncoding = contentEncoding;
}
httpResponse.Write(jsonResponse);
}
}
示例14: AddSessions
private void AddSessions(HttpResponseBase response, IEnumerable<Session> sessions)
{
foreach (var session in sessions)
{
response.Write("BEGIN:VEVENT\n");
response.Write("DTSTART:" + session.Start.Value.ToiCalTime(+5) + "\n");
response.Write("SUMMARY:" + session.Title + " with " + session.SpeakerName + "\n");
response.Write("DESCRIPTION:" + session.Abstract + "\n");
response.Write("COMMENT: Technology: " + session.Technology + "\n");
response.Write("COMMENT: Difficulty: " + session.Difficulty + "\n");
response.Write("LOCATION:" + session.Room + "\n");
response.Write("END:VEVENT\n");
}
}
示例15: Render
public static void Render(ControllerContext context, ViewDataDictionary viewData, TempDataDictionary tempData, HttpResponseBase response, IndexViewModel model)
{
RenderHeader(context, viewData, tempData, response, model);
RenderPreMessages(context, viewData, tempData, response, model);
foreach (var message in model.Messages.Messages)
{
switch (message.Type)
{
case FastLogReader.LineType.Join:
response.Write(RenderPartialViewToString(context, viewData, tempData, "~/Views/Unbuffered/MessageTypes/Join.cshtml", message));
break;
case FastLogReader.LineType.Quit:
response.Write(RenderPartialViewToString(context, viewData, tempData, "~/Views/Unbuffered/MessageTypes/Quit.cshtml", message));
break;
case FastLogReader.LineType.Message:
response.Write(RenderPartialViewToString(context, viewData, tempData, "~/Views/Unbuffered/MessageTypes/Message.cshtml", message));
break;
case FastLogReader.LineType.Meta:
response.Write(RenderPartialViewToString(context, viewData, tempData, "~/Views/Unbuffered/MessageTypes/Meta.cshtml", message));
break;
case FastLogReader.LineType.Action:
response.Write(RenderPartialViewToString(context, viewData, tempData, "~/Views/Unbuffered/MessageTypes/Action.cshtml", message));
break;
default:
goto case FastLogReader.LineType.Meta;
}
}
RenderPostMessages(context, viewData, tempData, response, model);
RenderFooter(context, viewData, tempData, response, model);
}