我想显示用户名密码以验证用户。在哪里更改它以获取身份验证弹出。下面是 webapi.config 文件
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
}
api控制器
[BasicAuthentication]
[Route("Reactor")]
[HttpGet]
public HttpResponseMessage Get()
{
string username = Thread.CurrentPrincipal.Identity.Name;
}