Category Archives: Code

Using IECapt.exe with IIS, ASP.net

asp.net

I used IECapt to generate screenshots of user websites, to display in their control panel.
Being a front-end dev, I don’t normally call a processes and envoke applications, but I was able to find some code to help me along. Unfortuatelty, I ran into some issues with permission when trying to execute the exe.

While developing on my local machice, I had no trouble generating screenshots with the following sample code.

public static void GenerateScreenShot(string url, string fileout){
            Process myProcess = new Process();  
            myProcess.EnableRaisingEvents = false ;  
            myProcess.StartInfo.RedirectStandardOutput = false;
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.FileName = @"" + System.Web.Configuration.WebConfigurationManager.AppSettings["IECaptPath"].ToString();
            myProcess.StartInfo.Arguments = @"--url=" + url + " --out=" + fileout + " --min-width=1200";
            myProcess.Start();  
            myProcess.WaitForExit();  
            myProcess.Dispose();
}

Unfortunately when deploying on IIS it encountered “Access is Denied” errors when trying to execute the exe. This mostly is because the IIS USER does not have permission to execute the file. Even though I tried to give it permission, it would not work.

After examining other code that uses Process(), I removed “EnableRaisingEvents”, “RedirectStandardOutput” and “UseShellExecute” and it finally worked!

public static void GenerateScreenShot(string url, string fileout){
            Process myProcess = new Process();  
            myProcess.StartInfo.FileName =  @"" + System.Web.Configuration.WebConfigurationManager.AppSettings["IECaptPath"].ToString();
            myProcess.StartInfo.Arguments = @"--url=" + url + " --out=" + fileout + " --min-width=1200";             
            myProcess.Start();  
            myProcess.WaitForExit();  
            myProcess.Dispose();
}

Javascript folder permission issue on Ubuntu, Zend

ubuntu and zend server

I recently deployed a Zend Framework site from my Windows Zend CE dev environment to the production Ubuntu 10.10 Zend CE server. Of course this task seems easy enough. Sure, the folder structure is different, but this should be easy as pie and work out of the box, right? Well not quite.

I copied my project to /var/www/myproject, added the my virtual hot to the httpd.conf file:

DocumentRoot /var/www/myproject/web_root 
SetEnv APPLICATION_ENV "development"

        AllowOverride All
        Order allow,deny
        Allow from all

After restarting apache2,

sudo service apache2 restart

my site was visible at http://localhost/ . Zend seemed to be working. CSS was loaded, images were displaying, however no JavaScript files were being loaded.
To debug, I right-clicked on the page and viewed the source to see if everything was inserting correcly with $this->headScript()->.

From the source page, I was able to click on the css path in:

	

which took me to and opened the css file. Great! So it is loading the CSS, as expexted.

So then I clicked on the JavaScript file:


which then took me to a 404 page, stating:
The requested URL /javascript/ipm/imageflow/js/imageflow.packed.js was not found on this server.

Strange, that folder and file is there, just as the css. I am able to access http://localhost/css and view the contents and access files.
I am not allowed to access http://localhost/javascript as I get a You don’t have permission to access /javascript/ on this server.

So, I don’t have the permission? I checked the folder permissions and every thing is correct. What can it be??
Solution
Strangely enough, Google only turned out 1 result pertaining to a similar issue. Link
The user states that he is using a .htaccess file to rewrite the url (this is was Zend Framework project does).
He can access everything except the http://domain.com/javascript/ folder

Below a commenter reveals a bug related to Debian (Ubuntu is based on Debian). Link

Basically there is a “javascript” library located at “/etc/javascript-common/” on Debian/Ubuntu. In the configuration file, there is a GLOBAL Alias “/javascript” that overrides my web server folder, http://localhost/javascript”. Kinda stupid, since ‘javascript’ folders are common in websites and applications. And to be honest, i usually put them in a ‘js’ folder, however as per a requirement, ‘javascript’ was the name of the folder.

2 Solutions:
#1 Change your website’s javascript folder to something other that ‘javascript’ and update your code, or

#2 Change the Alias in the javascript-common.conf file from /javascript to /javascriptlib

I chose the latter, since I did not want to mess with my code base.

sudo vi /etc/javascript-common/javascript-common.conf

Change:

Alias /javascript /usr/share/javascript/

To:

Alias /javascriptlib /usr/share/javascript/

Then restart apache:

sudo service apache2 restart

Navigate to your page or directly to the ‘javascript’ folder and you should now have access. šŸ™‚

Oh, what a night. My pain your gain!

Control Stretching Textboxes, Beyond 100%

asp.net

In ASP.NET I have created a form inside of a fixed width table, and added css to make my textboxes 100% width. For some reason, a long value assigned on the server side was stretching my textbox way past the the defined width of the table cell.

Initial Code:

Title

Solution:
Wrap the textbox inside a div with relative position, then give the textbox an absolution position.

Title

Accessing the web.config from a DLL

asp.netSometimes your website (or a site someone else made)Ā  will include a DLL that interface with your site.Ā  In a recent project, I encountered an issue where the DLL needed to utilize the web.config to access the database. With a quick search, I encountered many others with the same problem. There was a few solutions, but none of them work out of the box. With a little tweaking I was able to make it work.

In the web.config we have our connectionString:

<connectionStrings>
MyDBConnection" connectionString ="server=localhost;database=MyDB; user id=username; pwd=password"/>
</connectionStrings>

And to access it from the DLL:

string connStringĀ = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyDBConnection"].ToString();

And finally what they all missed:

Right-Click on your DLL project and Add a ReferenceĀ to System.Configuration

All solutions thatĀ I found said to simply add the ref to the page “using System.Configuration”, which did not work.