Rotativa file not found on server only - asp.net-mvc-4

I am using Rotativa ActionasPDF() to generate a pdf from a view in my MVC4 project. It works flawlessly on my local instance, but I just copied the entire solution to my server and it does not work. I get the error "The system cannot find the file specified", but I'm not sure what file it is talking about. I assume it is talking about the Rotativa dll, but I've got the generated Rotativa folder on my server as well. The solution is an exact duplicate as my local copy. My site is hosted on IIS 8, windows 2012 server. Research has told me I could have a permissions issue with some folder, but I'm not sure which ones they would be. I just set all my controller & views to 777 permissions for the time being. No luck. Any ideas to what I'm missing, or how I can make sure the dll is registered on my server?
Here is my controller action method:
public ActionResult DownloadFile(int id = 0)
{
var filename = string.Format("Invoice{0}.pdf", id);
return new ActionAsPdf("Invoice" + "/" + id, new { name = "Invoice" + id }) { FileName = filename, PageSize = Size.Letter, PageOrientation = Orientation.Portrait, PageMargins = new Margins(0, 0, 0, 0) };
}

Check if you add all files in rotativa directory on server-
libeay32.dll
wkhtmltopdf.exe
etc.

Old thread but I had the same issue so I wanted to share the solution for people searching in the future.
Ensure you have the correct VS Redistributable installed on the server, or files in the Rotativa folder.
Use the server IP address instead of the DNS name. I do not know why this works but will edit this if I figure it out.

You need to have Visual C++ Redistributable Packages on the server. You can download the packages from here: http://www.microsoft.com/en-gb/download/details.aspx?id=40784

You need update Rotativa, Rotativa.Core, Rotativa.MVC in Nuget

Related

Is there a consistent way for a .net core webapp & console app to determine path to datafiles folder?

I have two apps that share a data files folder. One is an asp.net core web app. The other is a .net core console app. Folder structure is:
WebApp
WorkflowApp
Datafiles
If I use any of these in the console app:
string en = Environment.CurrentDirectory;
string dr = Directory.GetCurrentDirectory();
string ad = AppDomain.CurrentDomain.BaseDirectory;
string sa = System.AppContext.BaseDirectory;
they all point to: workflow\bin\Debug\netcoreapp2.0
If I use them in the webapp, then en & dr point to "webapp" and the others point to "webapp\bin\Debug\netcoreapp2.0
I'm using appsettings.json to set the path to Datafiles. This file is shared by WebApp and WorkflowApp. I was setting it to "../Datafiles" and then getting the full path using:
Path.Combine(Directory.GetCurrentDirectory(), datafiles);
But this only works in WebApp. I would like to find a common method that works for both. And I don't want to set an absolute path in appsettings.json.
I could use AppDomain.CurrentDomain.BaseDirectory and then use:
#"..\..\..\..\Datafiles"
to move back from a "bin\Debug\netcoreapp2.0" folder. But this seems a bit convoluted. Is there a better way?
EDIT: An answer to this question might solve my problem (at least when in development): How can I get the path to the project folder (where the .csproj file is located) from in the code?
Try this way.
var requiredPath = "";
var address = "DataFiles";
var rootDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (rootDir != null)
{
requiredPath = Path.Combine(rootDir, address);
}
I would not let the application figure out the directory / path of where the data files are but rather externalize the paths into a config such as in appSettings.json or something similar.
If you then want to take it a step further and have the apps share the same config you can use a cetnralized store such as Consul or Etcd
https://github.com/etcd-io/etcd
https://www.consul.io/api/kv.html

Unable to configure SabreDAV to test Webdav and CardDAV

Steps I followed:
Downloaded the Sabredav zip file - unzipped it.
Downloaded apache webserver 2.2 and PHP 5.3
Then followed the instructions mentioned in the 'get Started' section on Sabredav website.
Created 'data and public' fiels (located them in /sabredav/vendor/)
Created the server.php file (located it in /sabredav/vendor/)
Now tried to open the server.php file in browser -
Here it opens using the file protocol..
Fails to open in expected - 'http ://mydomain/sabredav/server.php
Can anybody please help me on this ?
Thanks
In server.php, use the browser plugin tu see files in Public folder.
Your server must be like this:
include 'SabreDAV/vendor/autoload.php';
use
Sabre\DAV;
$rootDirectory = new DAV\FS\Directory('public');
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the correct information
$server->setBaseUri('/server.php'); // if its in some kind of home directory
// The lock manager is reponsible for making sure users don't overwrite each others changes. Change 'data' to a different
// directory, if you're storing your data somewhere else.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
$server->addPlugin(new \Sabre\DAV\Browser\GuessContentType());
$plugin = new \Sabre\DAV\Browser\Plugin();
$server->addPlugin($plugin);
// All we need to do now, is to fire up the server
$server->exec();

protected moodledata folder (for moodle 2.2 installation) in shared 1and1 hosting

I'm trying to install Moodle 2.2 on a shared linux 1and1 server. Following the web installation, I get to the step where it asks for the path of the moodledata folder. I've read that I need to put it somewhere without public access, which I believe means in a level above the public web root folder.
So if the public web root folder is: /homepages/44/d**/htdocs
the folder path should go be: /homepages/44/d**/moodledata
The problem is that when I want to create a folder there (connecting with ssh), I get a "permision denied" error.
I've contacted 1and1 and they're telling me that with my hosting package (dual unlimited) it's not possible to create folder in levels above the public web folder, and that I should upgrade the hosting package.
Is that the only way? Can I get a protected folder like moodle demands without having to upgrade the hosting package?
If you know what you are doing you can execute the following steps to install moodledata inside Moodle directory.
These modifications will turn off moodle verification about moodledata safety requisites.
You have to edit the file called in the root of moodle folder install.php.
Near line 230 put comments around the following code:
/*
while(is_dataroot_insecure()) {
$parrent = dirname($CFG->dataroot);
$i++;
if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
$CFG->dataroot = ''; //can not find secure location for dataroot
break;
}
$CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
}
*/
Near line 300 put comments around the following code:
/*
else if (is_dataroot_insecure()) {
$hint_dataroot = get_string('pathsunsecuredataroot', 'install');
$config->stage = INSTALL_PATHS;
}
*/

Zero dependency from the client configuration files for WCF services

Our aim is to have Zero dependency from the client configuration files for WCF services.
we are using ConfigurationChannelFactory() to create the channel and specify the ConfigSettings.
ConfigSettings is loaded using the following code
ConfigurationManager.OpenExeConfiguration(ConfigFilePath);
So we have to provide the ConfigFilePath here.
we have both windows and web clients.
we have used below approaches to find out the path
AppDomain.CurrentDomain.BaseDirectory + "bin\\" + executingAssembly.GetName().Name + ".dll"
Web client : AppDomain.CurrentDomain.BaseDirectory gives root folder of the
web applicaton so its works fine
Windows client : AppDomain.CurrentDomain.BaseDirectory gives path upto Debug/Release folder
so, its throws error
Assembly.GetExecutingAssembly().Location
Web client : Assembly.GetExecutingAssembly().Location gives path to the ASP.Net temp.
files , where we dont have the config files. So its throws an error.
Windows client : Assembly.GetExecutingAssembly().Location gives the correct location,
so its works fine.
In order to make it works in web clients, we have to add the following key in client's web.config files.
<hostingenvironment shadowcopybinassemblies="false">
but it adds a dependency to the clients.
Can you guys please help me to find the path without worrying about the clients?
have you tried this? I used GetCallAssembly() instead of GetExecutingAssembly() as this lives in a utility class in our project.
public static string AssemblyDirectory
{
get{
string codeBase = assembly.GetCallingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
Could you just probe both paths? In other words, check the Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin") folder and if you can't find the config file in there, check the Assembly.GetExecutingAssembly().Location folder instead? Since you indicate that the first approach works for web but not Windows clients, while the second approach works for Windows clients but not web, go with both!

DeploymentCatalog security error

I'm trying to use the DeploymentCatalog to load my service implementations by MEF. I have the implementation in a single xap. when I use the following code to download it , every thing is ok :
var catalog = new DeploymentCatalog("MyXap.xap");
catalog.DownloadAsync();
I put my xap on a remote server , say on http://ip:90/Myxap.xap, when I write the same code but with the uri , it throws a deployment exception:
var catalog = new DeploymentCatalog(new Uri("http://ip:90/MyXap.xap",UriKind.Absolute));catalog.DownloadAsync();
Any help .
Thanks in advance ...
If the XAP you are trying to download is hosted at a different domain (or different port, I think) than your Silverlight App is, you will need a cross domain policy file on the site that hosts your XAP to allow your Silverlight App to access it.
If that's not the problem, you'll need to provide more information. Edit your question to include the full text of the deployment exception you get.