Wednesday, March 28, 2012

ASP.NET AJAX not working for me??

Hi,

I am having a problem that is driving me crazy. I currently have my ASP.NET 2.0 website hosted with a hosting company and they claim to have AJAX extensions installed on their servers.

I created an asp.net page, put a simple label and button in an UpdatePanel, set the updatepanel to "Conditional", and yet is still causes a full page refresh when the button is clicked. I tried uploading the same exact page with same web.config to another web server I have and it worked properly there. What could be wrong with the hosted site and how can I fix it?

To further test the hosted site, I added some Controls from the Ajax Control Toolkit, such as Collapsible Panel, and that seemed to be working correctly even though the updatepanel is not. I even uploaded the DLL's to the bin folder.

What else can be causing this problem? I even have a different subdomain with the same hosting provider that seems to be running this page correctly. What settings can you think of that I should mention to the hosting company to fix them. I already alerted them of the problem and they believe they are doing everything correctly and that the problem lies on my side (which makes no sense to me since I know the code is fine since it runs perfectly on other servers).

Please help. Thank you.

First question I would ask is what version of ASP.NET Ajax do they have installed. Methods have moved to different assemblies over time. v1.0.61025 is the latest.

However, you also do not need to rely on them. You can include the DLL necessary and simply reference that from your project. You don't need to rely on GAC installed assemblies. Check your installation on your system for the System.Web.Extensions.dll and reference it. I think you also should remove the web.config lines that refer to the GAC entry. <add assembly= ......, but I haven't tried that to see if is necessary. If they don't have it installed properly, it may cause an error.


Ok, here's the deal. The hostnig company has the latest AJAX installed on their servers. In fact, I have about 5 websites hosted with this company (all on the same server). AJAX is working on 4 websites - just not working on on one site (for exapmple domain5.com). However, if I was to create a virtual directory pointing to that website it works (for example:www.domain4.com/domain5).

Similarly, I have AJAX working on domain4, but if I have a virtual directory on domain5 pointing to it (such aswww.domain5.com/domain4) then it does not work.

What can be causing this problem? I am thinking there must be a setting blocking AJAX on that domain/website. I noticed that this website has Frontpage Extensions installed. I don't know if that has anything to do with AJAX but I uninstalled it anyways and still doesn't work. Is there anything else - any settings or anything - that I should check that may be causing this problem.

Thanks.


We are having the same issue. Ajax won't work in virtual directories inside of other virtual directories. Have yet to figure out the solution. If anyone has any ideas post them please.

Thanks.


Neither one of you mentioned that you had any errors. However the most common cause of it not working is that the Virtual directory has not been made an Application in IIS. Use IIS to "Create" the application.


Yes, the sub application is set at an application. There are no errors, ajax just doesn't work. It just does full postbacks.

If you take the sub-applcation and remove it from being a "child" app...then it works perfectly. It just doesn't like being nested in another application.


Can application mapping be the cause of this problem. I currently have IIS application maps that cause .html and .xml pages to be run by the .NET framework. Is it possible that this can prevent AJAX from running in any way?


Since I had never tried nested virtual directories, I did a test on localhost using a physical directory created as an application. Inside this I put a virtual directory mapped to its own physical directory (created as an application by default). As another layer, inside this virtual directory, I put a virtual directory mapped to a third physical directory (also created as an application by default). All three function with a variety of Ajax tests including an UpdatePanel. I therefore doubt that common nested virtual directories are the root cause of the problem, unless there is a specific difference in Windows 2003 Server (which I doubt). I'll fire up my server and repeat it if that is suspect.

One thing I had to make sure of with the 2 virtual directories is that the mapped physical directories have to have permission added for the ASPNET user (XP), (or Network Service on server 2003). Otherwise I got a server 500 error after a request for authentication. Since you don't have errors, that is not the problem, but it is another aspect to keep in mind when mapping virtual directories.

However in reviewing the dialog above, there is a bit of confusing information in that two different types of virtual directories are being talked about. A virtual directory that maps to a physical directory on the same server (or even a UNC on another server which involves harder to set up permissions) are the common type. However a virtual directory which maps to a different URL is a re-direction and uses a different sequence of HTTP requests to get to the new directory. Maybe you could clarify how these are mapped if you know (hosting company may hide the implementation)

It is not necessary to have nested virtual directories of the former type for even a complex site. In two large corporations that I have worked at, we didn't have any nesting as there is no need to. You can create as many directory layers as you want before creating the last one as a virtual directory and your web site can have as many virtual directories as you want at the root or lower without any nesting necessary. The level at which an application is created in independent even though it is created by default on a new virtual directory. In a hosted environment it seems to me that the main method for separate domains is different web sites each with it's own applications and physical or virtual directories. So the shared hosting environments must use tricks to point to web sites. The key is getting to the bottom of how this works.

Other than that, if only the UpdatePanel is not working, that seems specific to a DLL loading (or not) and the suggestion that the directory Application is not configured properly is relevant. This should be correctable by deleting the virtual directory and recreating it (being careful to insure permissions for the physical directory are set)

If you want to go further, post the code you used and put it on the suspect web site along with a fresh copy of the template web.config. Send the URL (privately if you want) because I can analyze it with various tools and see what is actually happening when you hit the site.


I think I finally pinpointed this problem. It appears that my site at virtual directory domain1.com/ajaxvirtualdirectory is using the web.config file from the domain1 root directory (although I can't understand why). And when I access it from domain2.com/virtualdirectory it is using the domain2 web.config. Does that make sense?

I know this worked because I temporarily deleted the web.config from domain1 and replaced it with the web.config from domain2. Problem is, I still need the info from the original web.config so what fields do I need to include in the web.config to make AJAX work - or is there anything I can have in there (such as sessionstate=false or anything else). I tried combining the 2 but that didnt work.

Here;s what my web.config looks like

<configuration><!-- application specific settings --><appSettings><add key="ConnectionString" value="server=MYSERVERNAME;database=MYDB;uid=MYUSER;pwd=MYPW;"/><add key="FileDirectory" value="C:\MYFILEDIREC"/></appSettings><!-- forms based authentication --><system.web><compilation debug="true"><compilers><compiler language="vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".VB" compilerOptions="/define:Debug=True /define:Trace=True /imports:Microsoft.VisualBasic,System"/></compilers></compilation><!-- enable Forms authentication --><authentication mode="Forms"><forms name="MYFORMAUTH" loginUrl="login.aspx" protection="All" path="/"/></authentication><!-- enable custom errors for the application. Change mode to off to see what error is. RemoteOnly to hide errors --><customErrors mode="Off" defaultRedirect="Errors.aspx" /><!-- disable session state for application --><sessionState mode=""/><globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/><xhtmlConformance mode="Legacy"/><pages><namespaces><add namespace="Microsoft.VisualBasic"/></namespaces></pages></system.web><!-- set secure paths --><location path="PAGE1.aspx"><system.web><authorization><deny users="?"/></authorization></system.web></location><location path="PAGE2.aspx"><system.web><authorization><deny users="?"/></authorization></system.web></location><location path="PAGE3.aspx"><system.web><authorization><deny users="?"/></authorization></system.web></location></configuration>

No comments:

Post a Comment