locked
AjaxFileUpload causes javascript error with authorization RRS feed

  • Question

  • User-693047505 posted

    Using AjaxFileUpload in WebForms targetting .NET 4.5.1, I get a javascript error only under a certain condition. This is the error:

    throw "error raising upload complete event and start new upload"

    And the condition:

    Error only occurs when I include a web.config authorization element somewhere in the page's directory tree: deny users="?"

    If I comment out the condition to restrict to authenticated users, AjaxFileUpload works successfully. If I apply this as a single condition in the authorization element (deny users), then the error is thrown.

    Wednesday, December 18, 2013 1:08 AM

Answers

  • User-693047505 posted

    Workaround found:

    - remove authentication check from web.config (either root or nested) and replace with

    if (!User.Identity.IsAuthenticated) FormsAuthentication.RedirectToLoginPage();

    on every page in the directory where AjaxFileUpload is used.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 20, 2014 10:32 PM

All replies

  • User-1993059563 posted

    Add this entry in web.config

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <handlers>
          <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
        </handlers>
    </system.webServer>
    Wednesday, December 18, 2013 1:14 AM
  • User-693047505 posted

    Done, but then I get a duplicate entry error:

    "Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'AjaxFileUploadHandler'"

    The ajax handler is already in the site's web.config. The authenticated users web.config is nested.

    Wednesday, December 18, 2013 1:25 AM
  • User-1993059563 posted
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <handlers>
    <clear> <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/> </handlers> </system.webServer>
    Wednesday, December 18, 2013 5:42 AM
  • User-693047505 posted

    Still no good. This is the complete nested web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
     <system.web>
      <authorization>
       <deny users="?" />
      </authorization>
     </system.web>
       <system.webServer>
          <validation validateIntegratedModeConfiguration="false"/>
          <handlers>
             <clear />
             <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
          </handlers>
       </system.webServer>
    </configuration>

    When I modified it to the above, adding the clear element, it caused this error:

    HTTP Error 404.4 - Not Found. The resource you are looking for does not have a handler associated with it.

    I added the below to system.web, but it didn't help:

    <httpHandlers>
      <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
    </httpHandlers>

     

    Wednesday, December 18, 2013 6:25 PM
  • User-693047505 posted

    It's difficult when you are referred to links without reason, but...

    The first link is not applicable because I already had these elements in the site's web.config and the AjaxFileUpload works perfectly well in the site, except when it is nested in a directory requiring authenticated users - the original problem.

    The second is dealing with an earlier version of the toolkit (mine is 7.0607) which isn't working (mine is) and is using VS2012 (I'm in VS2013). I don't get the same errors - mine are javascript errors when isauthenticated is required.

    The third link is getting 404 errors connected with passing parameters to a page. I am not getting 404 errors and I do indeed pass parameters to the page in question with no problem at all. I only get a problem when I move the same page, which works perfectly, into a directory where authentication is required by a nested web.config. If I comment out <deny users="?" />, AjaxFileUpload again works perfectly.

    Wednesday, December 18, 2013 11:45 PM
  • User-933407369 posted

    hi rclancyr,

    Thanks for your reply.

    According to your description, i think the issue is due to your web.config.

    i check out your web.config file ,  i suggest you try to add the node to <system.web>.

    <system.web>
    <authorization>
          <deny users="?" />
        </authorization>
    
        <httpHandlers>
          <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
          <add verb="*" path="CombineScriptsHandler.axd" type="AjaxControlToolkit.CombineScriptsHandler, AjaxControlToolkit"/>
        </httpHandlers>
      </system.web>

    Please refer to the link below:

     Resolved: AjaxFileUploader April 2013 Upload Error

    http://ajaxcontroltoolkit.codeplex.com/workitem/27416

    if it is not working for you, you can consult your issue on ASP.NET  AJAX  for better solution and support. AJAX Experts there will further research this issue and provide you better support.

    Thursday, December 19, 2013 10:23 PM
  • User-693047505 posted

    The web.config changes did not help, but the link was very interesting because it shows other people also finding this problem and the connection to authentication and browsers. I can confirm now that my nested web.config with forced authentication works perfectly in Chrome. So this is now narrowed to an IE problem.

    I'll post something on the other thread and see if anybody can help. There are no solutions there yet.

    Thursday, December 19, 2013 11:24 PM
  • User-933407369 posted

    hi rclancyr ,

    Now, if you make sure that this is narrowed to an IE problem, i would suggest you post the thread to Technet forums - Internet Explorer

    for better solution and support. iE Experts there will further research this issue and provide you better support.

    If you think one reply help you, please mark it as An Answer.

    Thank you for your understanding.

    Wednesday, December 25, 2013 4:57 AM
  • User-693047505 posted

    Hi Happy Chen,

    When I say the problem is limited to IE, not happening with Chrome for example, does not suggest to me that it's an IE bug and should go on another forum. That seems to be passing the buck, and forwarding the issue to the wrong people. This is an ajaxfileupload problem which is only exposed when IE is the browser and authentication is required in a nested directory.

    I still haven't found a resolution or workaround.

    Tuesday, January 7, 2014 9:03 PM
  • User-227760790 posted

    you can create a simple which can easily reproduce your issue? 

    i want to test your simple , because i create a new but it cann't reproduce your issue.

    Tuesday, January 7, 2014 9:07 PM
  • User-693047505 posted

    Ok. I have created a simple web application which reproduces the issue. Zipped, it takes up 37MB. How should I send it to you?

    Tuesday, January 7, 2014 11:08 PM
  • User-227760790 posted

    wow! you don't need send your project to me, i only want to  the page and codes which are related to AjaxFileUpload causes javascript error with authorization.

    it should not take up 37MB, if there are necessary, you can zip them and upload to here: https://skydrive.live.com/.  

    And then you can fllow steps , Share>>Get a link.

    Wednesday, January 8, 2014 12:39 AM
  • User-693047505 posted

    I've uploaded it, but can't see any Help or instructions on what to do next. Is this URL sufficient?

    https://skydrive.live.com/#cid=2fac2baea4e05631

    Wednesday, January 8, 2014 1:21 AM
  • User-227760790 posted

    sorry, do you have a try to upload your link:https://skydrive.live.com/#cid=2fac2baea4e05631

    it cann't be shared by public pepole.

    Wednesday, January 8, 2014 1:47 AM
  • User-693047505 posted

    The file is there. How do I share it with you? When I select the file and try and share it, it requires an email address.

    Wednesday, January 8, 2014 2:30 AM
  • User-227760790 posted

    you need upload the file to Public Folder , end choose it and share , following steps below:

    1.Enter Public Folder

    2.Click Upload and Upload the file to Public Folder

    3.Choose the file 

    4.Share the file and click 'Get a link ' in dialog 

    5. click to 'Create link' and choose a option(Public) ,  the link seems like https://skydrive.live.com/redir?resid=859D9F18CD5F6C34%21105

    Wednesday, January 8, 2014 2:43 AM
  • User-693047505 posted

    I cannot see any link to anything called Public Folder. Search Public Folder returns nothing. I can only see SkyDrive where I am logged in. There is no logout function. Links available are Files, Recent, Photos and Shared. No sign of public.

    Wednesday, January 8, 2014 3:00 AM
  • User-227760790 posted

    okay.if so, now you post  the content from the three files which contains AjaxFileUpload.aspx ,AjaxFileUpload.cs and web.config .

    Wednesday, January 8, 2014 4:57 AM
  • User-693047505 posted

    Hi Galeny,

    I've reduced the zip file to 12mb and made it available on an ftp server:

    ftp://user34:shareMePub12@www.softdev.net

    Wednesday, January 8, 2014 5:32 AM
  • User-693047505 posted

    I've reduced the zip file to 12mb and made it available on an ftp server:

    (example code removed from server)

     

    Thursday, January 9, 2014 6:10 PM
  • User-227760790 posted

    hi ,

    i check out your project,  why you need to create a new web.config? it maybe cause the web.config missing somthing in sub directory.

    you can use <location> to achieve the target, as shown below:

    <location path="Ztesting123">
        <system.web>
          <authorization>
        <deny users="?" />
         </authorization>
          <httpHandlers>
            <add verb="*" path="Sub1.CaseManager" type="Sub1.CaseManager" />
            <add verb="*" path="CaseManager.Case" type="CaseManager.Case" />
          </httpHandlers>
        </system.web>
      </location>

    i would suggest you  delete web.config in sub directory , and then try to use the way above.

    Thursday, January 9, 2014 9:32 PM
  • User-693047505 posted

    Hi Galeny,

    Thank you for downloading and testing my app. I've made a few changes and created a new zipped version available from the same ftp address:
    - added login code so you can login as a validated user and test the problem properly
    - moved the authorization nested element to the root web.config file as a location element as you suggested, though I don't see why this would be significant because nested web.config files are recommended for this purpose

    The changes made little or no difference:
    - Chrome works authenticated or not authenticated (deny users commented out)
    - IE only works if deny users is commented out. Rather than a js error though as before, it now just seems to time out

    Please verify you get the same results.

    Friday, January 10, 2014 7:03 PM
  • User-693047505 posted

    (example code removed from server)

    I've spent more time reducing the example to its basic elements. There is a page to login in/out and a file upload page. In web.config, there is a location element where authentication is required (deny users = ?). If you do not comment this line out and browse using IE, a js error occurs when uploading files. If you comment the line out, IE works fine. Chrome works in all circumstances.

    Tuesday, January 14, 2014 1:00 AM
  • User-693047505 posted

    Workaround found:

    - remove authentication check from web.config (either root or nested) and replace with

    if (!User.Identity.IsAuthenticated) FormsAuthentication.RedirectToLoginPage();

    on every page in the directory where AjaxFileUpload is used.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 20, 2014 10:32 PM
  • User79986525 posted

    Hi ,

    I get the solution if the issue .

    Within your inner web.config 

    modify it like this 

    <?xml version="1.0"?>
    <configuration>
    	<system.web>
       
    		<authorization>
    			<allow roles="Admin,Landscape Architect,Dealer" />
    			<deny users="?"/>
         
    		</authorization>
        
    	</system.web>
      <location path="AjaxFileUploadHandler.axd">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
    </configuration>

    Hope this will help you out 

    Monday, February 3, 2014 9:06 AM
  • User-693047505 posted

    Thank you for the suggestion, but it didn't work for me. I still got js errors when uploading files. My workaround above continues to work.

    Tuesday, February 4, 2014 8:04 PM
  • User79986525 posted

    Hi ,

    Try this 

    Add this to your Main Web.config 

     <location path="AjaxFileUploadHandler.axd">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <system.web>
        <httpHandlers>
          <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
          <add verb="*" path="CombineScriptsHandler.axd" type="AjaxControlToolkit.CombineScriptsHandler, AjaxControlToolkit"/>
        </httpHandlers>
    </system.web>
     <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <handlers>
          <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
          <add name="CombineScriptsHandler" preCondition="integratedMode" verb="*" path="CombineScriptsHandler.axd" type="AjaxControlToolkit.CombineScriptsHandler, AjaxControlToolkit"/>
        </handlers>
    </system.webServer>

    //Folder web.config 

    //Add this to your sub folder web.config 

    </system.web>
    <location path="AjaxFileUploadHandler.axd">
    <system.web>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>
    </location>
    </configuration>

    I to Have same problem but it resolve by doing as above .

    Hope this will help you out 

    Wednesday, February 5, 2014 4:46 AM
  • User-693047505 posted

    Again, thank you but it didn't help. Same result.

    The structure of the config file is interesting because there are two system.web sections at different levels.

    Wednesday, February 5, 2014 5:44 PM