Why is the form action attribute empty on production server?
After deploying a ASP.NET WebForms application to a production server some of the ajax calls has stopped working for me. After some debugging I found out that the following statement (in the internal client-method WebForm_DoCallback) was causing the problem:
xmlRequest.open("POST", action, true);
The problem seemed to be that the action-variable was empty so after checking the rendered html I found out that the form-tag rendered on the production server looks like:
<form method="post" action="" id="Form1">
However, on my developer machine I get the following:
<form method="post" action="default.aspx" id="Form1">
So, why would the action-attibute render on my dev.machine but not on the production server? This seems to be the case only for one specific web form, when I look on other pages the action-attribute renders correctly.
开发者_如何学GoAny suggestions or ideas would be helpful!
I too have this issue. I installed dot net framework 4 on the production Windows 2003 R2 server, got the application running on IIS6, set it's framework to 4.0, put it in it's own app pool, then I got that. I've also noticed that it isn't loading up jscript one my login page, so perhaps it's a security issue?
Interesting though that when I go to the default page by selecting the site url http://mysite the action is not put in But when I go there directly using an actual page (even though it's rendering exactly the same content) it puts the action in correctly.
Anyhow, my workaround was to set make the form runat=server (it may have been already) and then set the Action attribute on the server to the current Page.Path (could have been a different property, I forget) and that solved that particular problem.
However, I did come across a breaking changes document for the dot net 4 framework that talks about the blanking out of the action attribute: http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes see the section titled "Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode"
I'm probably way off, but since you asked for any suggestions...
I don't know much about ASP, but in PHP, post
variables are passed from the name
attribute of the inputs, not the id
attribute of the form itself. For instance:
<form id="test" method="post" action="test.php">
<fieldset>
<input name="firstname" type="text" />
<input name="lastname" type="text" />
</fieldset>
</form>
And on the server_side, if you did:
print_r($_POST);
You would get:
Array (
[firstname] => Joe
[lastname] => Smith
)
Other than that, the only things that come to mind are:
- Make sure your form validates (the HTML itself),
- Check to see if your DTD is set to Strict or Transitional,
- Test to see if the issue is browser-side by testing on multiple variables,
- Throw in a
type="hidden"
input with a pre-set value, to see if that gets back to the server.
I doubt any of this is going to solve the problem, but I hope at the very least one of my suggestions uncovers some aspect that leads to a solution.
ASP.NET in .NET 3.5 Service Pack 1 introduced some breaking changes regarding HTMLForm, so it may be worth checking that both servers have exactly the same framework version.
"Previous versions of ASP.NET always ignored the action attribute if it was present in the declarative markup for a element. Developers should remove the action attribute from their declarative markup to return to the original behavior where ASP.NET renders the postback Url."
Worth a shot.
精彩评论