Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Using a console app, how can I log in to Episerver


Using a console app, how can I log in to Episerver CMS so I can access an API that I need to be logged in for.

I then want to be able to use HttpRequest's to bring back data from the API that needs CMSAdmin credentials for example.

The version we are using is Episerver 7.5 and the authentication is Forms Authentication

Jul 30, 2020 14:26

Hi bazzagan,

"Fake" web browser request from console app: you would need to request the login form page (and your console client needds to have cookies enabled) so that you get the needed Episerver CMS cookies (see the link for the cookie names) and then you would do a post with username, password and the needed cookies (the xsrf cookie value needs to be also sent in the hidden field of the form, look the names from the login page html source). if the login succeeds then you have in the response cookies your roles etc and then can call your API wit those cookies and get the OOB Authorize attribute fuinctionality what I assume you are using at the moment). The console app request implementationis then naturally up to you if you will use HttpClient or WebRequest to make the actual requests to the login page.

Another approach might be use some sort of API key that the client sends when requesting data from the API and in your API instead of AuthorizeAttribute you use your custom implementation to validate that the client is allowed to do the request.

Jul 31, 2020 8:00

Thanks Antti. That is just what I needed. I grabbed the cookies and posted them with each request using HttpClient and all was happiness. Have a great day :)

Aug 14, 2020 9:27

Hi bazzagan, good to hear.

If I may ask one thing, could you mark my reply as answer :D so others know too there is a solution for your question.

Aug 14, 2020 10:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.