当前位置: 首页>>代码示例>>C#>>正文


C# Response.Start方法代码示例

本文整理汇总了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();
 }
开发者ID:shz,项目名称:pointy,代码行数:7,代码来源:Program.cs

示例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();
 }
开发者ID:shz,项目名称:pointy,代码行数:7,代码来源:Program.cs

示例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();
 }
开发者ID:shz,项目名称:pointy,代码行数:15,代码来源:Program.cs

示例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();
        }
开发者ID:shz,项目名称:pointy,代码行数:33,代码来源:Program.cs

示例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();
 }
开发者ID:shz,项目名称:pointy,代码行数:17,代码来源:Program.cs

示例6: Some2

 public async Task Some2(Request req, Response res)
 {
     await res.Start();
     await res.Write("SomeController.Index");
     await res.Finish();
 }
开发者ID:shz,项目名称:pointy,代码行数:6,代码来源:Program.cs


注:本文中的Response.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。