どのような基本認証が取り扱うHttpListenerす。
-
05-09-2019 - |
質問
このように聞こえるかもしれないが基本的な問題であり、Httpプロトコル101.私は、こうした困難の理解にどのよう基本認証です。私の実施をwindowsのサービスが必要です。私のユーザー名とパスワード認証のユーザーがカスタムユーザーのお店です。また、私の回数を最小限に抑えるためにログインの話としてログインの話を表す呼び出してSQLサーバーです。私の始めにこのようなこと:
のんので、UserAuthorized機能については私のカスタムログインする。でも、思いがします。な基本認証を維持すでにログインされている場合は、キャッシュのスレッドを安全に解決しているつもりだったが、います。
あたいものとなっていることをすることでユーザ認証およびオブジェクトの作成されたスレッドのリスナーを参照してその後のコールバックのためのユーザが接続します。でListenerCallbackがstaticのプレの設定顔は丸させることに成功した。
おかげさまで又はその助けにより、いただき、ありがとうございまやStackOverflow.
public void ThreadProc() {
string uriPrefix = ConfigurationManager.AppSettings["ListenerPrefix"];
HttpListener listener = new HttpListener();
listener.Prefixes.Add(uriPrefix);
listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
listener.Start();
Console.WriteLine("Start listening on " + uriPrefix);
Console.WriteLine("Press Control-C to stop listener...");
while (listening) {
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
result.AsyncWaitHandle.WaitOne();
}
}
public static void ListenerCallback(IAsyncResult result) {
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
WebDavEngine engine = new WebDavEngine(context.User);
context.Response.SendChunked = false;
FileLogger.Level = LogLevel.Debug;
engine.IgnoreExceptions = false;
if (UserAutorized(context)) {
try {
engine.Run(context, listener.Prefixes);
engine.CommitTransaction();
} catch {
engine.RollBackTransaction();
} finally {
engine.CloseConnection();
}
} else
context.Response.StatusCode = 401;
if (context.Response.StatusCode == 401)
ShowLoginDialog(context, context.Response);
try {
context.Response.Close();
} catch {
// client closed connection before the content was sent
}
}
private static bool UserAutorized(HttpListenerContext context) {
HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity;
if (!identity.IsAuthenticated) {
string username = identity.Name;
// workaround for Windows Vista Basic authentication. User name may be submitted in the following format: Machine\User.
int ind = username.LastIndexOf('\\');
if (ind > 0)
username = username.Remove(0, ind + 1);
Console.WriteLine("Trying Authentication since identity is NOT authenticated");
return false;
} else {
Console.WriteLine("identity.IsAuthenticated: " + identity.IsAuthenticated.ToString());
return identity.IsAuthenticated;
}
}
編集: +1の文書だけで、本当にcaparisonの認証制度とどのように。場合を除いて、掛この間違っているのは、このダイジェストスキームが維持できるということもこの"セッション"もしくは少なくとも、有効期限を再私のカスタム認証を行います。
解決 2
の仕様、私の活動を高く評価します。かったので管理し解決問題となったスペック関連ではなく、デザイン/開催。
他のヒント
HTTP基本 が必要で、ログイン資格情報ク.HTTPを持たない概念のセッションもしたりすることはできません教えて人口が減ったのならば、"ログインしています。
所属していません StackOverflow