Monday, March 14, 2011

How to connect to Excel Services with FBA

Lets say you have a site that uses forms based authentication, like an internet facing site. And then lets say that you are using Excel Services on the same farm.

So what you need is to make a cookie:

ExcelWebService.ExcelService excelService = new ExcelWebService.ExcelService();
debugWriterOutput("eService: " + excelService.Url);

excelService.CookieContainer = new CookieContainer();

ExcelWebService.Status[] status;

internal static Cookie FBACookieAuthentication(ExcelWebService.ExcelService excelServiceSoapClient)
Authentication.Authentication auth = new Authentication.Authentication();
auth.CookieContainer = new CookieContainer();

LoginResult result = auth.Login("LoginName", "Password");

CookieCollection cookies = auth.CookieContainer.GetCookies(new Uri(auth.Url));

Cookie authCookie = cookies[result.CookieName];

return authCookie;

No comments: