Using Aspose Cells on a Web Server

I am trying to use Aspose Cells in a Web SErvice. The idea is the user requests a data export, the data is formated and put into a spreadsheet using Aspose then sent as a stream or bytes back to the user to be saved to their hard drive and viewed using Excel.

My problem is the license - where does it go on the web server how does it get "referenced" etc. I have it in several locations on the web server (localhost) right now and I keep getting this error:

"Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

What am I doing wrong or missing? I have used cells fine when it was all in the client code but having it in the web service is proving to be difficult.

Hi,

Well, I think the issue looks to be of security permission sets for the IO operation and does not concern to Aspose.Cells by any means. I think you are not allowed to access the file system completely. To confirm this exception, you may try to run the code to open or access the file without involving Aspose.Cells API, e.g…, FileStream fs = File.Open(…)

I think you need to modify the proper security settings for your requirements. You need to have to assign Administrative role for your web application.

Moreover, I think you may try to put the license file on some folder in your web project/application and then may use Server.MapPath to access the file in the folder, e.g
string path = HttpContext.Current.Server.MapPath(“~”);
string licFile = path + “bin\Aspose.Cells.lic”;
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(licFile);

Also, for an ASP.NET project, you should pick Application_Start or Session_Start event and put the licensing code there as the licensing code needs to evaluated only once for the whole lifetime of the web application.


Thank you.

I will try reading the file but I thought that was what CellsLicense.SetLicense was trying to do already. (obviously not working)

I am not following most of your reply. In part because you are talking about a web page and my question is about a web service. (ie not httpcontext, no app or session start)

It sounds like you are saying that the user attempting to access the file must have admin rights on the server. I'm not sure I can do that. I can do that in the test environment and will see if that is the problem, if so it will probably mean we can not use aspose.

I am able to read the file using:

Dim fstr As New FileStream(binPath & "\Aspose.Cells.lic", FileMode.OpenOrCreate, FileAccess.Read)

However when I send the same path and file name into CellsLicense.SetLicense I get an error:

"Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

So the web service can access the file but Aspose can't, Suggestions?

I switched to using a stream to set the license and that works fine.

Problem solved.