本文整理汇总了C#中Response.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Start方法的具体用法?C# Response.Start怎么用?C# Response.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.Start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Something
public async Task Something(Request req, Response res, string echo)
{
await res.Start();
await res.Write("SomeOtherController.Something");
await res.Write("\n" + echo);
await res.Finish();
}
示例2: Index
public async Task Index(Request req, Response res)
{
await res.Start();
await res.Write("SomeController.Index");
throw new Exception("bad news everyone");
await res.Finish();
}
示例3: Error
/// <summary>
/// Writes an error to the response with the specified code and message
/// </summary>
/// <param name="res">Response object to write to</param>
/// <param name="code">HTTP error code</param>
/// <param name="message">Message to send</param>
private async Task Error(Response res, int code, string message)
{
var data = Encoding.UTF8.GetBytes(message);
res.Headers["Content-Length"] = message.Length.ToString();
res.Headers["Content-Type"] = "text/html; charset=utf-8";
await res.Start(code);
await res.Write(data);
await res.Finish();
}
示例4: ServeDirectory
/// <summary>
/// Serves a somewhat-nice HTML directory listing to the response. Note that
/// it doesn't check permissions or anything, so it's a potential security
/// problem. You've been warned!
/// </summary>
/// <param name="res"></param>
/// <param name="path"></param>
/// <returns></returns>
async Task ServeDirectory(Response res, string path)
{
var info = new DirectoryInfo(path);
string[] dirs = Directory.GetDirectories(path);
string[] files = files = Directory.GetFiles(path);
// Prep the response
res.Headers["Content-Type"] = "text/html; charset=utf-8";
await res.Start();
await res.Write(String.Format("<!doctype html>\n<html><head><title>Directory Listing: {0}</title></head><body>", path));
// Write the directories
await res.Write("<h2>Directories:</h2><ul>");
foreach (var dir in dirs)
await res.Write(string.Format("<li><a href=\"{0}/\">{0}</a></li>", dir.Substring(path.Length)));
// Write the files
await res.Write("</ul><h2>Files:</h2></ul>");
foreach (var file in files)
await res.Write(string.Format("<li><a href=\"{0}/\">{0}</a></li>", file.Substring(path.Length)));
// Wrap up
await res.Write("</ul></body></html>");
await res.Finish();
}
示例5: ServeFile
/// <summary>
/// Serves the specified file to the response. This does not check permissions and
/// the like -- in fact it does no error checking whatsoever.
/// </summary>
/// <param name="res"></param>
/// <param name="path"></param>
/// <returns></returns>
async Task ServeFile(Response res, string path)
{
var info = new FileInfo(path);
res.Headers["Content-Length"] = info.Length.ToString();
res.Headers["Content-Type"] = MimeType.ByExtension(info.Extension).ToString();
res.Headers["Last-Modified"] = info.LastWriteTimeUtc.ToString("R");
await res.Start();
await res.WriteFile(info);
await res.Finish();
}
示例6: Some2
public async Task Some2(Request req, Response res)
{
await res.Start();
await res.Write("SomeController.Index");
await res.Finish();
}