Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if an aspx page was called from Server.Execute?

I have the following example 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've tried checking the Referrer but this only seems to return domain and not the script.

I'm using ASP.NET Web Forms on .NET 3.5

like image 418
GateKiller Avatar asked Dec 03 '22 08:12

GateKiller


1 Answers

Since Server.Execute runs the new page with the same context as the original page, all the properties of Request should still reflect the original request to Webpage.aspx (except for CurrentExecutionFilePath, which hopefully contains "/Script.aspx"). Request.Path should contain "/Webpage.aspx", while Request.Url will give the full Uri object if you need to see the domain or querystring.

You can also add values to Context.Items before calling Server.Execute and read them in Script.aspx

like image 154
stevemegson Avatar answered Dec 27 '22 15:12

stevemegson