ASP.NET PostBackUrl not working on Server
April 2, 2010
Scenerio: I have a simple contact form in which I want to post to a different page.
Pretty simple, just set the PostBackUrl property of the button to the page I want to post to. It works like it should locally. When I deploy it to the server, Rackspace Cloud, it doesn’t work.
Research: After Binging for a while I found that the issue was due to a javascript error. If you VIew Source of the page, you’ll notice that the rendered html uses javascript to perform the PostBack.
<input style=”border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px” id=”imgButton” class=”submit” onclick=”javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("imgButton", "", false, "", "/quick-contact.aspx", false, false))” src=”/i/qcsubmit.gif” type=”image” name=”imgButton” />
I then was able to capture the javascript error in IE. *Sidenote, what is a good way to do this? I ended up putting my cursor in the form, hit enter and quickly clicked on the browser stop button. There must be a better way.
![]()
“Webform_PostbackOptions” is undefined.
Ok…. Why is that? I found this in the comments at a blog post on http://pocketnerd.blogspot.com/2008/01/webformpostbackoptions-is-undefined.html
“I was getting this error in a load balanced production environment, but once the network admin turned on sticky sessions, all the errors went away. I assume it was trying to load the .axd file from the other web server and perhaps that caused a security problem which didn’t allow the file to load. Not sure but just thought I’d share what fixed it for me. “
I don’t have server access when hosting in the Cloud.
The WebForm_PostBackOptions function should be in the WebResource.axd file that you’ll see is referenced in the html on load.
<script src=”/WebResource.axd?d=Ttwk99ZBtJ8argpvGbO64g2&t=633750447951477990″ type=”text/javascript”></script>
I tried browsing to this file and this indeed was the issue, 404 Not Found.
Solution: I loaded the page locally. Viewed Source, grabbed the WebResource.axd and querystring, browsed to this file. This gave me the output of the javascript. I copied that all and placed it into a postbackfix.js file. I then referenced this js file on the page. Uploaded the new js and aspx files. Works now.
This took me a few hours of banging my head (not to Quit Riot) to figure out. Hope this helps someone else.
Sending email on Rackspace Cloud using asp.net
January 20, 2010
I have hosted with the Rackspace Cloud now for about two years. I really couldn’t be happier with them and would recommend them to anyone. The one thing I have seemed to have issues with is sending emails from my web applications. After talking with support and doing some testing I have a solution that should last.
Here is an example of a basic contact form.
First set the smtp information in the web.config
<system.net> <mailSettings> <smtp> <network host="mail.emailsrvr.com" userName="info@mydomain.com" password="mypassword" port="25"/> </smtp> </mailSettings> </system.net>
I put this at the very bottom of the web.config just before the closing tag.
Note that the userName and password must be of a valid email address of the domain you are sending from. Make sure to set this up through their control panel.
I also add in the appSettings of the web.config the email addresses of whom to send it to and the subject line. Just best practices.
<appSettings> <add key="mailTo" value="joel@mydomain.com"/> <add key="mailSubject" value="Contact Form inquiry"/> </appSettings>
Now my example is of an asp.net web application in c#. I am going to assume everyone knows how to setup the page, lets go to the code-behind.
You will need to add these three lines to your using block.
using System.Web.Configuration; using System.Text; using System.Net.Mail;
The submit button handler:
/// <summary>
/// Handles the contact form submit
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void imtbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
StringBuilder body = new StringBuilder();
body.AppendFormat("Company Name: {0}{1}", txtCompany.Text, Environment.NewLine);
body.AppendFormat("Contact Name: {0}{1}", txtName.Text, Environment.NewLine);
body.AppendFormat("Phone: {0}{1}", txtPhone.Text, Environment.NewLine);
body.AppendFormat("Email: {0}{1}", txtEmail.Text, Environment.NewLine);
body.AppendLine();
body.AppendLine("Message");
body.AppendLine(txtMessage.Text);
MailMessage message = new MailMessage(txtEmail.Text, WebConfigurationManager.AppSettings["mailTo"], WebConfigurationManager.AppSettings["mailSubject"], body.ToString());
SmtpClient client = new SmtpClient();
client.Send(message);
pnlForm.Visible = false;
lblMessage.Visible = true;
}
Pretty simple stuff, the import part is system.net in the web.config, making sure you have the correct host and port and a valid email.
You would think they would have this in their knowledge base, but as of this writing they don’t. I hope this helps someone.
Install WordPress on Mosso (Cloud Sites)
April 28, 2009
*UPDATE*
Chad Keck recently put a video tutorial which explains how to do this in a much simpler manner than what I have described below. I suggest you first try and follow his video. http://www.rackspacecloud.com/cloud_hosting_demos/cloud_computing_word_press_install
Here is a quick step-by-step guide to install WordPress on a site hosted through Mosso (Cloud Sites).
Assumptions:
- You know how to manage your domain
- You know how to upload files to your website
1. Set up your Cloud Site.
1a. Login into Mosso then navigate to Cloud Sites under Hosting in the left-hand menu.
1b. Below the currently hosted websites you will see a section Add a New Website. Fill in your details here.
![]()
1c. Add the website as you have any others, make sure to allow for 1 database and set the Default Technology to Linux/Apache/PHP
2. Download WordPress. You can get the download at, http://wordpress.org/download/.
3. Extract the zip file to your local computer.
4. Open the extracted directory wordpress and rename the file, “wp-config-sample.php” to “wp-config.php”
5.Set up your MySql database for the website.
5a. After your site is created you should be in the management section of the newly created site. Click on the Features tab to go add a new database.
5b. Once you have navigated to the Features page click on the “Add” button in thee Databases section at the top.
make sure to remember or write down what you fill out in the next two steps.
5c. Step 1 – Give your database a name, I usually choose the domain name of a shortened version of it. Choose MySql * as your Database type. Continue.
5d. Step 2 – Enter a database username, I always use the same as you used for the database name to keep it simple. Enter and confirm your password. Finish.
6. Update the WordPress file, wp-config.php.
6a. While the database is being created you can go ahead and update this file. Open the file up in your favorite text editor. You should see where you need to enter your database name, database username, password and host. The name, username and password you just created.
6b. The host can be found once the database is created under the Features tab you should be able to click on the name of your database to edit it. On this page you will see a section title Database Information. You will see “Hostname” under the Name and Hostname section. Use this to replace, localhost below.
update the fields in red below
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘putyourdbnamehere‘);
/** MySQL database username */
define(‘DB_USER’, ‘usernamehere‘);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘yourpasswordhere‘);
/** MySQL hostname */
define(‘DB_HOST’, ‘localhost‘);
/** Database Charset to use in creating database tables. */
define(‘DB_CHARSET’, ‘utf8′);
/** The Database Collate type. Don’t change this if in doubt. */
define(‘DB_COLLATE’, ”);
6c. Update the Authentication Unique Keys in this file. In the file it gives a handy link to generate the keys, https://api.wordpress.org/secret-key/1.1/. Open up a browser and go to that url. Copy the output of it and replace what is in the file with it.
6d. Save the wp-config-.php file.
7. Upload all the wordpress files to your site via ftp. Go grab a bite to eat, this may take a few minutes.
8. Now you’re ready to start configuring the blog. In your browser navigate to: [yourdomain.com]/wp-admin/install.php. If you haven’t set the domain to be live yet you can use the testing url here.
Fill out the info on this page.
Uncheck “Allow my blog to appear in search engines..” Once you have the blog ready to go live you can check in this settings.
Click the button Install WordPress.
9. Note the username and password and then “Log In”. I just copy the password to my clipboard.
10. Login and change password.
Login and click on “admin” in the upper right corner of the page. This will take you to your profile where you can update your password to something you’ll remember.
11. Create and Upload a .htaccess file so you can have friendly urls for your posts.
11a. Open up a text editor and create a new file. Add the text below:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
11b. Save the file as “.htaccess”.
11c. Upload this file to the root of your blog.
12. Update the blog to allow for friendly urls.
12a. In the WordPress admin section under Settings in the menu found at the bottom click on Permalinks.
Under Common Settings update it to one that you like and Save Changes.
13. Delete the index.html file located in the root directory. This is just a placeholder page created by Mosso until you have your site ready.
YOU’RE DONE. You should now be able to go to your domain and see your blog. Some of the steps could be done out of order but following it will get your blog up and running. I hope you find this beneficial.
Automate your database backups on MOSSO
March 21, 2009
Today I learned the hard way that your data isn’t always safe.
I created an Admin interface for one of my clients that basically manages an Image Gallery. The gallery allows for a Category and SubCategory structure.
I received a call at about 10:30am asking where all of his images were? After doing some investigating, my heart stopped, I found the bug.
I had a bug in my SubCategory_Delete proc that didn’t have the WHERE SubCategoryId = @SubCategoryId clause. When a user would delete a SubCategory it would delete all the photos in the image gallery instead of just the photos in that specific SubCategory.
My initial thought was to get the backup. Well it turns out backups aren’t created automatically. This is something you need to manual do when creating a database.
I was fortunate enough to have a great Customer Service rep, Sean Fox, that somehow managed to convince MOSSO’s IT team to create a backup for me from their disaster recovery backups. Thanks MOSSO.
So after first going to my client with my tail between my legs I was able to go back to him as a hero. “Your data has been saved!”
I’ve since put in place a backup plan for all of my databases hosted at MOSSO. I found this article in their Knowledge Base: http://help.mosso.com/article.php?id=346 for MSSql. There is one for MySql, http://help.mosso.com/article.php?id=356.
I modified it a bit by creating a console app that is scheduled nightly and ran on my server. This way only I can execute the backup.
My advice is to put this in place before you need it, not afterwards.
-
Categories
- asp.net (11)
- Blog (1)
- Business (5)
- Conferences (1)
- Errors (3)
- Portfolio (2)
- Reviews (2)
- SQL Server (3)
- Tips (1)
- Uncategorized (1)
- Web Development (13)
-
Archives