在.NET HTTP认证 [英] HTTP Authentication in .NET

查看:150
本文介绍了在.NET HTTP认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能产生等同于下面code一个.NET?

Is it possible to create a .NET equivalent to the following code?

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>

我希望能够定义一个静态的用户名/密码在web.config中也是如此。这是很容易做到在PHP中,没有看到任何解释如何做到这一点的MSDN

I would like to be able to define a static user/password in the web.config as well. This is very easy to do in PHP, haven't seen anything explaining how to do this in MSDN.

我要的是这样的:

推荐答案

要实现一样在PHP code将作为直接通过的 Reponse.AppendHeader()

The easiest way to achieve the same as with the PHP code would be to directly send the same headers via Reponse.AppendHeader().

不过我建议你阅读 ASP.NET窗体身份验证教程

这篇关于在.NET HTTP认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆