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


C# HttpListener.AuthenticationSchemes属性代码示例

本文整理汇总了C#中System.Net.HttpListener.AuthenticationSchemes属性的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.AuthenticationSchemes属性的具体用法?C# HttpListener.AuthenticationSchemes怎么用?C# HttpListener.AuthenticationSchemes使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Net.HttpListener的用法示例。


在下文中一共展示了HttpListener.AuthenticationSchemes属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimpleListenerWithUnsafeAuthentication

public static void SimpleListenerWithUnsafeAuthentication(string[] prefixes)
{
    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");
    // Set up a listener.
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    // Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
    // If NTLM is used, we will allow multiple requests on the same
    // connection to use the authentication information of first request.
    // This improves performance but does reduce the security of your 
    // application. 
    listener.UnsafeConnectionNtlmAuthentication = true;
    // This listener does not want to receive exceptions 
    // that occur when sending the response to the client.
    listener.IgnoreWriteExceptions = true;
    Console.WriteLine("Listening...");
    // ... process requests here.

    listener.Close();
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:28,代码来源:HttpListener.AuthenticationSchemes

示例2: Main

//引入命名空间
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Mail;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Xml;

public class MainClass
{
    public static void Main()
    {
        using (HttpListener listener = new HttpListener())
        {
            listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
            listener.Prefixes.Add("http://localhost:8080/");
            listener.Prefixes.Add("https://localhost/");
            listener.Start();

            HttpListenerContext ctx = listener.GetContext();
            ctx.Response.StatusCode = 200; 
            string name = ctx.Request.QueryString["name"];

            StreamWriter writer = new StreamWriter(ctx.Response.OutputStream);
            writer.WriteLine("<P>Hello, {0}</P>", name);
            
            writer.WriteLine("<ul>");
            foreach (string header in ctx.Request.Headers.Keys)
            {
                writer.WriteLine("<li><b>{0}:</b> {1}</li>",header, ctx.Request.Headers[header]);
            }
            writer.WriteLine("</ul>");

            writer.Close();
            ctx.Response.Close();
            listener.Stop();
        }
    }
}
开发者ID:C#程序员,项目名称:System.Net,代码行数:45,代码来源:HttpListener.AuthenticationSchemes


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