show source

  • Thread starter Thread starter Seb
  • Start date Start date
S

Seb

With php I can simply append a s to the file extension, eg. .phps and
if the user request the file the source will be shown in the browser.

Is there a semilar functionality for aspx pages?

best regards,
seb
 
Seb has brought this to us :
With php I can simply append a s to the file extension, eg. .phps and
if the user request the file the source will be shown in the browser.

Is there a semilar functionality for aspx pages?

best regards,
seb

What source do you mean? There is the aspx file itself, it's codebehind
file and there may be any number of supporting classes.

Depending on the compilation model used, all of these could be absent
from your server!

As far as I know, it is not possible to request any of these sources
(fortunately!). The retrieval of some support files (*.config for
example) is even actively blocked bij ASP.Net!

Hans Kesting
 
Seb has brought this to us :




What source do you mean? There is the aspx file itself, it's codebehind
file and there may be any number of supporting classes.

aspx, cs and so on.
Depending on the compilation model used, all of these could be absent
from your server!

True, but they aren't :)
As far as I know, it is not possible to request any of these sources
(fortunately!). The retrieval of some support files (*.config for
example) is even actively blocked bij ASP.Net!

It's so I could easily show my source to a group like this.


best regards,
seb
 
I do not get your problem...

If you have developed an application then you should have a source.
If you have not then it would be a security problem to allow you to see the
cource.

PS: I tried to add .phps instead of .php on the
http://www.php.net/archive/2008.php
and all i do not see any souce, only custom 404 page


George.

Seb has brought this to us :




What source do you mean? There is the aspx file itself, it's codebehind
file and there may be any number of supporting classes.

aspx, cs and so on.
Depending on the compilation model used, all of these could be absent
from your server!

True, but they aren't :)
As far as I know, it is not possible to request any of these sources
(fortunately!). The retrieval of some support files (*.config for
example) is even actively blocked bij ASP.Net!

It's so I could easily show my source to a group like this.


best regards,
seb
 
Yea, I guess you could add a Handler,

I would probably analyze query string or path for something like
mypage.aspx?source=1
or
mypage.aspx/source

The problem with mypage.aspx.source is that you would need to register
extension .source with ASP.NET dll (in IIS Management console)
 
I do not get your problem...

If you have developed an application then you should have a source.
If you have not then it would be a security problem to allow you to see the
cource.

Not if you want to expose the source to a group like this.
PS: I tried to add .phps instead of .php on thehttp://www.php.net/archive/2008.php
and all i do not see any souce, only custom 404 page

If you change the extension to .phps if will present the source code,
not output of the parsed php code.
 
Hello George,

Granted, you should have the source code already, but for easier access via
web, the only way I can think to do this would be to create an HTTP Handler,
set it up on the web.config file, and register the file extensions in the
app config on the IIS server. The HTTP handler would intercept, for example,
yourpage.aspx.source calls to the web server and depending on the name prior
to '.source' the handler would grab that file and read the contents out to
you on the webpage, checking code-behind and inline page code. That seems
the best method to me...

If you don't know how to write an HTTP Handler and set it up, there's basically
no way other than to have the original source... Or you could just remove
the aspx mapping in the app config, but then the site wouldn't work at all.

Inspired by http://msdn.microsoft.com/en-us/library/ms228090.aspx

Quick and dirty:
using System.Web;
using System.IO;


public class SourceHandler : IHttpHandler
{
public SourceHandler()
{
}

public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
HttpServerUtility Server = context.Server;

string file = File.ReadAllText(Server.MapPath(Request.FilePath));
file = Server.HtmlEncode(file);

file = file.Replace("\r\n", "<br />");
file = file.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");

//surround this with valid html
Response.Write(file);
}

public bool IsReusable
{
// To enable pooling, return true here.
// This keeps the handler in memory.
get { return false; }
}
}



Thanks a lot :)
 
Yea, I guess you could add a Handler,

I would probably analyze query string or path for something like
mypage.aspx?source=1
or
mypage.aspx/source

The problem with mypage.aspx.source is that you would need to register
extension .source with ASP.NET dll (in IIS Management console)

Simply add the handler to web.config
Anyway, i never had need to display the source for myslef.... :)

You should share more :)


best regards,
seb
 
Simply add the handler to web.config
Which version of IIS are you running you code under? Cause it's not that
simple...
If you running it under the Server that comes with Visual Studio (ASP.NET
Development Server) then you are in for some problems once you move it to
production....

George.

Yea, I guess you could add a Handler,

I would probably analyze query string or path for something like
mypage.aspx?source=1
or
mypage.aspx/source

The problem with mypage.aspx.source is that you would need to register
extension .source with ASP.NET dll (in IIS Management console)

Simply add the handler to web.config
Anyway, i never had need to display the source for myslef.... :)

You should share more :)


best regards,
seb
 
Which version of IIS are you running you code under? Cause it's not that
simple...
If you running it under the Server that comes with Visual Studio (ASP.NET
Development Server) then you are in for some problems once you move it to
production....

I realized that... Is there a way to make this work with a standard
host? surftown in my case... or do I need access to iis manager?

best regards,
seb
 
Back
Top