WebRequest a classic asp page

Last post 05-17-2008 8:17 AM by jchandra. 4 replies.

Sort Posts:

  • WebRequest a classic asp page

    05-17-2008, 4:32 AM
    • Loading...
    • ds321uk
    • Joined on 05-03-2008, 6:32 AM
    • Posts 7

    I am trying to execute the code on a classic asp page from an asp.net page, both the asp and aspx files are in the same folder on the server.

     

    I want to call this asp page as I would like to copy some files on the server which are out the web applications folder but still in my ftp area of the server, I can do this in classic asp, but I can’t do it in asp.net as the security level has been set to medium.

     

    I am working with vb.net 2.0

     

    If any one has any ideas I would be appreciate it.

     

    Thank you

     

  • Re: WebRequest a classic asp page

    05-17-2008, 6:26 AM
    • Loading...
    • jchandra
    • Joined on 05-15-2008, 5:36 AM
    • Jakarta, Indonesia
    • Posts 197

    You should be able to do this without any problem AFAIK.

    see the following example...

     

        protected void Button1_Click(object sender, EventArgs e)
        {
            string url = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port;
            for(int i = 0; i < Request.Url.Segments.Length - 1; i++)
            {
                url += Request.Url.Segments[i];
            }
            url += "test.asp";
            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
            WebResponse response = request.GetResponse();
    
            string result;
    
            using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }
    
            Response.Write(result);
        }
    }
     Shouldn't be too hard to change this to VB
    Jimmy Chandra
    Blogging at Incoherent Rambling

    Mark this post as Answer if you think it helped you solve the problem.

  • Re: WebRequest a classic asp page

    05-17-2008, 7:35 AM
    • Loading...
    • ds321uk
    • Joined on 05-03-2008, 6:32 AM
    • Posts 7

    I have got this from your code:

      

        Sub CallASP(ByVal srtURL As String)
            Dim url As String = Request.Url.Scheme + "://" + Request.Url.Host.ToString + ":" + Request.Url.Port
            For i As Integer = 0 To request.Url.Segments.Length - 2
                url += request.Url.Segments(i)
            Next
            url += srtURL
            Dim request2 As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            Dim response As WebResponse = request2.GetResponse()
    
            Dim result As String
    
            Using reader As New System.IO.StreamReader(response.GetResponseStream())
                result = reader.ReadToEnd()
            End Using
        End Sub

     I get this error:

    System.FormatException: Input string was not in a correct format

    on this line:

    Dim url As String = Request.Url.Scheme + "://" + Request.Url.Host.ToString + ":" + Request.Url.Port

  • Re: WebRequest a classic asp page

    05-17-2008, 7:40 AM
    • Loading...
    • ds321uk
    • Joined on 05-03-2008, 6:32 AM
    • Posts 7

    Fixed the earlier error changed the line to:

     

    Dim url As String = Request.Url.Scheme & "://" + Request.Url.Host.ToString & ":" & Request.Url.Port

     I not get this error:

    Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

     on this line:

    Dim request2 As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

     

  • Re: WebRequest a classic asp page

    05-17-2008, 8:17 AM
    Answer
    • Loading...
    • jchandra
    • Joined on 05-15-2008, 5:36 AM
    • Jakarta, Indonesia
    • Posts 197

    Try adding <trust level="high" originUrl="whatever your site url here" /> to your web.config system.web section. if that doesn't work try level="full" if not, well, hehehe.

    Jimmy Chandra
    Blogging at Incoherent Rambling

    Mark this post as Answer if you think it helped you solve the problem.

Page 1 of 1 (5 items)