Skip to main content

Show Source Code of Aspx webpage and code file in Browser window

Language


For show your source code of aspx page, u have to used System.IO namespace 1) Read Default.aspx File Aspx file contain both html and aspx server control tag so used File Stream and read a aspx file. Server.HtmlEncode (String val) takes a string argument and return all aspx code as a string. string FilePath = Server.MapPath("Default.aspx"); //get the physical path StreamReader sReader = new StreamReader(FilePath); //Create object of StreamReader string FileContent = string.Empty; FileContent = "<pre>" + Server.HtmlEncode(sReader.ReadToEnd()) + "</pre>"; lblaspxsource.Text = FileContent; sReader.Close(); 2)Read Default.aspx.cs File Use tage to show your aspx(C#,VB) code into browser window string FilePath = Server.MapPath("Default.aspx.cs"); StreamReader sReader = new StreamReader(FilePath); string FileContent = string.Empty; FileContent = "<pre><code>" + Server.HtmlEncode(sReader.ReadToEnd()) + "</code></pre>"; lblsourcecodeCSFile.Text = FileContent; sReader.Close();
 

Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byAnonymous (not verified)on Sat, 11/28/2009 - 14:53

can u send projects on online course using asp.net with source code
Submitted byAnonymous (not verified)on Sat, 04/24/2010 - 03:32

hi, Do you know how we can read the source code off a aspx in php

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.