There are some easy ways to authenticate yourself to your web service, and you don’t need to use anything fantastic or even follow some standards, such as OAuth or OpenID (not that it's bad, but it looks like you want to get in the door with something simple).
, , , AuthorizeAttribute ( , System.Web.Http, MVC). OnAuthorization . . , MVC Api Action System.Web.Http.AuthorizeAttribute - ?
, . - - MyID: [SomeRandomString]. OnAuthorization , , 401 ().
, , , https://, , /, , IIS, . , - HTTP .
public class PasswordAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
try
{
string password = actionContext.Request.Headers.GetValues("Password").First();
if (password != "abc123")
{
actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
return;
}
}
catch (Exception e)
{
actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
return;
}
}
}
[PasswordAuthorize]
public class YourController : ApiController
{
}
- IIS, , " ", , http://www.sslshopper.com/article-how-to-create-a-self-signed-certificate-in-iis-7.html
http://msdn.microsoft.com/en-us/library/ms733791.aspx
netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
, - api https, http://pfelix.wordpress.com/2012/02/26/enabling-https-with-self-hosted-asp-net-web-api/