答案 0 :(得分:2)
您的示例中的用户名和密码使用HTTP基本身份验证 - 它们不是URL的一部分,而是包含在标头信息中。您可以在ASP.NET中访问此信息,请参阅此文章:Basic Authentication with Asp.Net WebAPI
public class BasicAuthenticationAttribute : System.Web.Http.Filters.ActionFilterAttribute {
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) {
if (actionContext.Request.Headers.Authorization == null){
// No Header Auth Info
actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
} else {
// Get the auth token
string authToken = actionContext.Request.Headers.Authorization.Parameter;
// Decode the token from BASE64
string decodedToken = Encoding.UTF8.GetString(Convert.FromBase64String(authToken));
// Extract username and password from decoded token
string username = decodedToken.Substring(0, decodedToken.IndexOf(":"));
string password = decodedToken.Substring(decodedToken.IndexOf(":") + 1);
}
}
}