view source


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: view source

  1. #1
    John A Grandy Guest

    view source

    In VB.NET / ASP.NET, I am trying to provide a "view source" button on my
    ..aspx page which, when pressed, would cause the browser to show the
    underlying html/aspx source code for the current page

    ASP.NET *dynamically* creates the actual .aspx pages which are delivered to
    the client. The delivered pages may differ from the initial static .aspx
    pages which are located at (for example) :

    c:\inetpub\wwwroot\webapplication1\webform1.aspx

    On the client side, the page viewed will exist as a local file located on
    the client machine at (for example):

    c:\documents and settings\<user name>\local settings\temporary internet
    files\webform1.aspx

    (w2k, ie6)

    On the server side, I don't know where the **dynamically** generated file is
    located.

    If I knew where the dynamic file was located, potentially I could somehow
    use Response.WriteFile() to send the contents across ... ?








  2. #2
    Phil Weber Guest

    Re: view source

    > In VB.NET / ASP.NET, I am trying to provide a "view source"
    > button on my .aspx page which, when pressed, would cause
    > the browser to show the underlying html/aspx source code
    > for the current page


    John: Try this:
    http://www.web-source.net/javascript_view_source2.htm
    ---
    Phil Weber



  3. #3
    John A Grandy Guest

    Re: view source

    Interesting Phil. But I'd like to do it using ASP WebControls ... I want to
    get away from editing HTML. Plus, I tried interspersing that code into the
    design view of the aspx page and it's tough to figure out how to place it.

    What I've been doing is trying a LinkButton with this code behind it:

    Dim fsCurrentPage As FileStream

    Dim strFullPathCurrentPage As String

    strFullPathCurrentPage =
    Server.MapPath(Request.ServerVariables("PATH_INFO"))

    fsCurrentPage = New FileStream(strFullPathCurrentPage, FileMode.Open)

    Response.Write(Server.HtmlEncode(fsCurrentPage.ToString()))

    but I got a security error; strangely, the {machinename}\ASP.NET process
    does not have rights directly access the aspx files in

    c:\inetpub\wwwroot\<app name>

    I wonder if there was some way to use a virtual path to grab a file, then
    the security error would go away





  4. #4
    Phil Weber Guest

    Re: view source

    > I'd like to do it using ASP WebControls ... I want to
    > get away from editing HTML.


    John: Try this:

    Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    Dim script As String = "<script language=""javascript"">" & _
    "function viewSource() { window.location = " & _
    "'view-source:' + window.location.href }</script>"
    RegisterClientScriptBlock("ViewSource", script)

    End Sub

    Then set your HyperLink's .NavigateURL property to
    "javascript:viewSource()".
    ---
    Phil Weber



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center