本文整理汇总了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();
}
示例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();
}
}
}