Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Ajax issue, error c00c023f

    Hmm, i'm loading the following page in my browser and it works fine:
    "http://localhost/testing/testing.aspx?url=C:\inetpub\wwwroot\testing\image2.jpg&dir=clockwise"

    Here is the code for that page.
    Code:
    <%@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Web" %>
    
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    	string url = Request.QueryString["url"];
    	string rotate_dir = Request.QueryString["dir"];
    	
    	//create an image object from the image in that path
    	System.Drawing.Image img = System.Drawing.Image.FromFile(url);
    	
    	//Rotate the image in memory
    	if (rotate_dir == "clockwise")
    	{
    		//Rotate clockwise
    		img.RotateFlip(RotateFlipType.Rotate90FlipNone);
    	} else if (rotate_dir == "anticlockwise") 
    	{
    		//Rotate anti-clockwise
    		img.RotateFlip(RotateFlipType.Rotate90FlipXY);
    	}
    	
    	//Delete the file so the new image can be saved
    	System.IO.File.Delete(url);
    	
    	//save the image to the file
    	img.Save(url);
    	
    	//release image file
    	img.Dispose();
    }
    </script>
    Here is the code for the ajax request
    Code:
    function test() {
    	var http = xmlhttp();
    	http.onreadystatechange = function () {
    		if (http.readyState == 4 || http.status == 200) {
    			document.getElementById("test").innerHTML = (http.responseText);
    		}
    	}
    	http.open("GET", "http://localhost/testing/testing.aspx?url=C:/inetpub/wwwroot/testing/image2.jpg&dir=clockwise", true);
    	http.send();
    	
    }
    Just codes a quick function to test this, and yes it does actually work fine on other files. Nothing is put into the div either so nothing is actually being returned, and at one point when I clicked it the image did rotate but still returned the errors. Won't rotate at all now though.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Try specifying the address of the page as http://localhost/testing/image2.jpg instead of C:\inetpub\wwwroot\testing\image2.jpg and see if that makes a difference.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    martynball (07-29-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Now I get this returned
    Code:
    URI formats are not supported. 
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
     Exception Details: System.ArgumentException: URI formats are not supported.
    
    Source Error: 
    
    
    
    Line 11: 	
    Line 12: 	//create an image object from the image in that path
    Line 13: 	System.Drawing.Image img = System.Drawing.Image.FromFile(url);
    Line 14: 	
    Line 15: 	//Rotate the image in memory  
    
     Source File:  c:\inetpub\wwwroot\testing\testing.aspx    Line:  13

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    It seems that testing.aspx is not outputting something. What is the expected output of that page?

  • Users who have thanked glenngv for this post:

    martynball (07-30-2013)

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Nothing at the moment, the image should simply rotate, but it doesn't.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    If there is no output, then what do you expect the responseText to be?

    Code:
    document.getElementById("test").innerHTML = (http.responseText);

  • Users who have thanked glenngv for this post:

    martynball (07-30-2013)

  • #7
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    It should be nothing, there should be no response. The image in the folder should rotate, but it isn't.

    If I load the URL from the browser directly it does rotate, loading it using ajax I get an error and no rotation.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Where would you see the images rotating if there is nothing on the page?

  • Users who have thanked glenngv for this post:

    martynball (07-30-2013)

  • #9
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    In Windows Explorer (for now)

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Oh ok. Maybe the forward slash in ajax call should be changed to backward slash? Though I know Windows should have no problem using \ or / in the file paths.

    Btw, you should not pass the whole path. For security reasons, you should allow passing just the part of the path or the filename only. Then in your code behind, prepend the base path.

  • Users who have thanked glenngv for this post:

    martynball (08-01-2013)

  • #11
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    I will try that, and shouldn't have any issues with security really as this application isn't public, it will be setup on laptops and used by employees.

  • #12
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Getting closer I think.

    I have this string
    string url = "C:\inetpub\wwwroot\testing\image.jpg";

    Here is the error
    Code:
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS1009: Unrecognized escape sequence
    
    Source Error:
    
    
    Line 8:  {
    Line 9:  	//string url = Request.QueryString["url"];
    Line 10: 	string url = "C:\inetpub\wwwroot\testing\image.jpg";
    Line 11: 	string rotate_dir = Request.QueryString["dir"];
    Line 12:

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    You should escape the backslash.
    Code:
    string url = "C:\\inetpub\\wwwroot\\testing\\image.jpg";
    Or use verbatim string literals.
    Code:
    string url = @"C:\inetpub\wwwroot\testing\image.jpg";

  • Users who have thanked glenngv for this post:

    martynball (08-01-2013)

  • #14
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    You legend, it works!

    One more question, if I was to loop through an array of images to rotate would the server become overloaded?

    Should I put a short delay between rotations ?

  • #15
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    I can't really tell. You have to try to put tons of images in the folder and check.

  • Users who have thanked glenngv for this post:

    martynball (08-02-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •