How to determine if an aspx page has been called from Server.Execute?

I have the following page structure:

  • Webpage.aspx
  • Script.aspx

If I call Server.Execute("Script.aspx")from Webpage.aspx, how can I detect in Script.aspx that it was called from Webpage.aspx and not directly from a web browser?

I tried checking Referrer, but this only returns the domain, not Script.

I am using ASP.NET Web Forms on .NET 3.5

+4
source share
6 answers

In Script.aspx.cs you can just check Request.Path compared to the current execution path.

if ( Request.CurrentExecutionFilePath == Request.Path ) 
{
   //This has been called from a web browser
} else {
   //This has been executed from the file Request.Path
}

Why?

, Server.Execute. , Request.Path Script.aspx.cs Server.Execute - .aspx.cs, , "/Webpage.aspx".

, - Script.aspx, Request.Path Script.aspx.cs "/Script.aspx". CurrentExecutionPath script, .

, .

+6

Server.Execute , , Request - Webpage.aspx( CurrentExecutionFilePath, , , "/ Script.aspx" ). Request.Path "/Webpage.aspx", Request.Url Uri, .

Context.Items Server.Execute Script.aspx

+12

, , Request.IsLocal.

0

querystring Script.aspx( , WebPage.aspx).

Server.Execute("script.aspx?xFrom=webPage.aspx")

EDIT: , , , webpage.aspx.

EDIT2: Request.Url?

0

HttpRequest.FilePath URL- , "Script.aspx".

( , .Net .)

0

, - IHttpHandler, , HttpContext.PreviousHandler . , (, ) , PreviousHandler, stevemegson HttpContext.Items Server.Execute.

0

All Articles