My brother was recently forced to use Ajax, so he used asp.net ajax to implement it. Well, it was simple, and it was done in a few clicks... But the problem came out immediately, and it conflicted with my url rewriting. My url rewriting module was written by myself. I made a filter and solved the problem of incorrect submission location of the server form. But now, as long as I use ajax for postback for the second time, a 404 error will be reported. , I came to cnblogs and saw someone talking about this problem, and actually said that it can be solved by modifying the action. I was very confused, I have solved the action problem a long time ago, and it seemed to be the best solution... So I opened a hook program. , I captured the final post address of each IE, and found that after the second postback of ajax, his submission address (not the action of the page, but something called form._initialAction generated by js inside aspnet ajax) will be Of course, there will be problems if you change it to a relative path, so if you find that url rewriting conflicts with ajax, please pay attention to testing this problem, and don't let things go online before discovering the problem...Don't think that everything will be fine if you modify the action. ...In fact, I think this problem is a defect of "ASP.NET AJAX RC1". Why use relative paths? Wouldn't it be better to be honest and just take the action instead of doing so many strange things? Of course, I don't understand his design principles. I guess he has his own reasons. The relevant code to solve this problem is as follows:
<!--Ajax Script Manager-->
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script type="text/javascript">
Sys.Application.add_load(function()
{
var form = Sys.WebForms.PageRequestManager.getInstance()._form;
var href = window.location.href;
if(href.indexOf("?") > 0)
{
href += "&a=" + Math.random();
}
else
{
href += "?a=" + Math.random();
}
form._initialAction = href;
form.action = href;
});
</script>
You may have noticed that this code adds a random number to the address. It is actually to solve the latter problem (browser cache conflict), but it is not solved well. . .
OK, the rewriting conflict was resolved, and the second problem occurred again. . . After speculation, I think it is a browser cache problem. I made a function to add and delete tags. Needless to say, adding is to put an ImageButton in the Repeater. Through its click event, use CommandName to add the current The tag was sent back and deleted. At this time, the problem occurred. After I added multiple tags and clicked one of them to delete, the tags list in the updatepanel returned to the state before adding the first one, so I suspected that it was cached by the browser. Problem, I stupidly added Response.Cache.SetNoStore(); in the server code.
Response.Cache.SetLastModified(DateTime.Now); I hope it can solve the problem, but in fact it is useless, haha, so I used the above js code to add a random number to the end of the url when assigning form._initialAction. number, the result is still invalid. . . I guess the problem occurs when this random number does not get the effect every time, but I really don’t have time to understand the principles of asp.net ajax in depth, so I hope that friends who know how to solve this problem can help me solve it first, Xiaodi Go back and study it again.
http://www.cnblogs.com/cnlamar/archive/2007/01/08/614671.html