R – Using built in ASP.NET membership to secure web services

asp.net-membershipweb services

Is it possible to use the built in ASP.NET membership provider to secure a web service?

I have a SQL Server database already setup with my membership and now I want to provide a web service that only members are allowed to use. Is it possible to authenticate against this (if so how?) or do I need to have a seperate type of authentication for the web services?

Best Answer

I think that I can do something like this. I didn't have a server to upload and test right now, but will mark this as the answer if it works:

    [WebMethod]
    public string HelloWorld(String username, String password)
    {
        bool isAuthenticated = Membership.ValidateUser(username, password);

        if (isAuthenticated)
            return "Hello World";
        else
            return "You do not have access to this resource.";
    }
Related Topic