问题
I created an OData service using VS Lightswitch with an endpoint like this:
http://mydevsite.com/lightswitchapps/mydata/products.svc
The service is secured with forms authentication. When I put the url into a browser I am asked for credentials.
I want to build a console app in C# to consume the service. But I can't find any examples of how to authenticate.
I've worked through this which consumes the Northwind service:
http://msdn.microsoft.com/en-us/library/hh868028%28v=vs.103%29.aspx
But I need help with the authentication.
Can anyone point me in the right direction?
回答1:
I had the same issue in LightSwitch OData Service.
Here is the solution :
Uri uri = new Uri("https://localhost:5487/ApplicationData.svc/");
var container = new MyNameSpace.ApplicationData(uri);
container.Credentials = new NetworkCredential("username", "password");
回答2:
It seems that your question is similar to this one: HttpClient and forms authentication in C# Please reference it.
来源:https://stackoverflow.com/questions/22563839/authenticate-lightswitch-odata-service-that-uses-forms-authentication