This project is read-only.

Submitting contact form with AJAX (JQuery) not working.

Topics: Customizing Orchard, General, Troubleshooting
Mar 9, 2011 at 5:12 PM

I have a form that was pasted in one content item in the CMS.

This form is a basic contact form, the only difference is that it must submit through Ajax to a processor file that will generate an email. When the form is outside the CMS, it works just fine. But when the form is in the Orchard framework it won't work.

I have turned off the editor to make sure the form code is not touched.

Here the JQuery Ajax I am using:



var dataString = 'fName='+ fName + '&fTitle='+ fTitle + '&fCompany='+ fCompany + '&fEmail=' + fEmail + '&fPhone=' + fPhone + '&fOptout=' + fOptout;  
//alert (dataString);return false;
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/form_pc_aspx",
data: dataString,
dataType: "json",
//changed to error for testing purposes. test is error
success: function() {
return false;


What I have noticed is that Orchard will not allow me to access files directly.  So when I check the form_pc.aspx in the browser (located in the same directory as Orchard) it returns a 404, or 500.

I will really appreciate any help on this.  This is the last part of the project and we are stuck.


Mar 9, 2011 at 6:04 PM

You'd have to relax the settings in web.config and allow for the aspx extension to be handled, but the better question would be why you're not putting that logic into a controller action?

Mar 9, 2011 at 6:57 PM


Thank you so much for your help.  I am afraid I am not aware how to put the logic into a controller action, so my next best option is a plain POST to the processor aspx file.

What would be the right web.config setting that would allow me to run this processing aspx file without compromising Orchard's security?

Again, your help is greatly appreciated.


Mar 9, 2011 at 7:47 PM

You should put that file into a separate folder so that you can put a web.config file in there that will affect only that folder and leave the rest unaffected. You might have to make that its own IIS web application, depending on what settings you need to override.

If you look at the web.config at the root of Orchard, you'll see that we remove a lot of assemblies. You will probably need to add some of those back into your local config. We are also clearing all HttpHandlers, so you'll have to add back at least the one for aspx (you can find the original in the machine.config)

Mar 9, 2011 at 8:11 PM

I am sure what you are saying makes a lot of sense to ASP developers, but in my case I am in the exact same place.

The new folder is called /proc

The new folder has a web.config:

<?xml version="1.0" encoding="UTF-8"?>
<customErrors mode="Off" />
<directoryBrowse enabled="true" />
<clear />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="Default.cshtml" />
<add value="index.php" />
<add value="index.html" />
<add value="" />
<add value="default.html" />
<add value="Default.aspx" />

I don't think it can get more open than this.

The /proc folder has one aspx file.

When I visit the /proc folder, I get 404.

When I visit the /proc/form_proc.aspx  I get 404

A nightmare in which files and folders don't exist, but I can see them, access them, change them and do everything with them but not run it in the browser.

No wonder nobody likes .NET

Mar 9, 2011 at 8:40 PM

> "No wonder nobody likes .NET"

I'm going to ignore that and try to help you anyways ;)

In any web server, you can lock down what gets served to the user and what does not. This is necessary, otherwise you would expose secrets just too easily. Nothing specific to .NET here.

The way you do that is by specifying in config what file extensions should be mapped to what handlers. In the case of Orchard, we have actively removed everything so that we only serve what is known and expected for the application to run. This, again, is a security measure.

You are explicitly saying that you don't want to use the programming model of the application, but instead use what you know (which is fine), which is different. Because of that, you have to enable that model to work. You need a little help doing that, which again is fine.

Default documents are not going to help here because those specify what is going to be served if only the directory name is given instead of the full path to the file.

What is going to help on the other hand is to allow for the aspx extension to be handled. This should do the trick:

<?xml version="1.0"?>
          <add assembly="mscorlib" />
          <add assembly="Microsoft.CSharp, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          <add assembly="System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          <add assembly="System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          <add assembly="System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True" />

Mar 9, 2011 at 8:54 PM

We have progress!  Now the 404s take 10 minutes to load.

Thanks anyway.

Mar 9, 2011 at 9:04 PM

Mmmh. I tried this before I wrote it you know? In other words I'm trying to help and spending time on this... Can you try first with a very simple hello world page in a folder where you also put the above web.config and tell me what you see when you navigate to the page? (I noticed that your jQuery has _aspx at the end of the URL instead of .aspx).

Mar 9, 2011 at 9:13 PM

Here, try it yourself.

The Orchard installations is here:

The form I am referring to is here:

The folder with the processing aspx is here:

The JQuery with the Ajax is here: (look for the comment "//Send Calculator Form with AJAX" to see the part I am referring to.

The proc/ folder has a web.config exactly as what you provided.  Still 404s.  I even created a virtual directory for the proc folder, still 404.

Please don't take my frustration on your help, I greatly appreciate it, it is just that seems ridiculous that controlling how to list the content of a folder requires such a baroque approach.

Mar 9, 2011 at 9:20 PM

But your jQuery code is *not* pointing at that isave supply calculator folder. It's pointing at That is at the root and is indeed returning 404. Where did you put the form_pc.aspx file and where did you put the new web.config?

Mar 9, 2011 at 9:31 PM

Well, I am changing the path again and again until I hit the jackpot, I don't know what else to do.  I have placed that /proc folder on every single subfolder of the Orchard install to try one that allows me to run.

The one that is 100% sure to have the form_pc.aspx in it is but pointing to that folder either in the Jquery or browsing to the folder stills gives 404

Let's do it again

Orchard Install:
Calculator Page:  (Already part of the CMS this page is a content item in Orchard, not a subfolder in the system. the isave-suppy-calculator is a slug not a folder)
Jquery with AJAX Code:
Folder with aspx file the AJAX is looking for form_proc.aspx: (This is a folder in the root of
Config you provided was placed in:

Result: 200
Calculator page: 200
Jquery with Ajax: 200
Folder /proc: 404
form_proc.aspx inside the /proc: 404
Directory browsing (even though I have allowed in IIS) for /proc : 404



Mar 9, 2011 at 9:53 PM

Ca you zip your proc folder and send it to me (bleroy at microsoft)?

Mar 9, 2011 at 10:26 PM

ZIp has been sent to your email.  Please let me know if an admin account for our Orchard install is also helpful.

Mar 9, 2011 at 11:57 PM

Here's a simple one that worked with your files:

<?xml version="1.0" encoding="UTF-8"?>
        <handlers accessPolicy="Script">
            <add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
Mar 10, 2011 at 2:26 PM


It worked perfectly.  Suicide/rampage averted; you saved lives today.

Thank you so much.

Mar 10, 2011 at 9:04 PM