I'm newbie in web programming with C#, and developing WCF RESTful services for Mobile Applications.
In REST service class, I set up response code as HTTP 401 Unauthorized, but it redirects other page suddenly.
Here's my service code:
[WebGet]
public string login(string id, string password)
{
if (Membership.ValidateUser(id, password))
{
FormsAuthentication.SetAuthCookie(id, false);
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
return "Login Succeeded";
}
else
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
return "Login Failed";
}
}
If login is succeeded, it works fine, but if I enter wrong password, this page redirects to
http://localhost:50195/login.aspx?ReturnUrl=%2fuser%2flogin%3fid%3dtest74323%26password%3d535201&id=test74323&password=####
I thinks there's auto-redirecting to user login page configuration, how can I off that configuration? I think problem is complicated while I'm using form authentication in the service.
I'm using form authentication with login cookie, I know that is not RESTful way, but I can't help it due to integration with other services. (in-company matter, hh)
And if there's some not-wrong but better way to implement login service, please let me know.
How can I show better error message when I access service with web browser? I know there's nothing to return if login is succeeded, I thought I'd better show string value if client accesses with web browser.