如何检测如果一个aspx页面从使用Server.Execute叫什么名字? [英] How to detect if an aspx page was called from Server.Execute?

查看:137
本文介绍了如何检测如果一个aspx页面从使用Server.Execute叫什么名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例页面的结构:

I have the following example page structure:

  • Webpage.aspx
  • Script.aspx

如果我称之为使用Server.Execute(Script.aspx)从Webpage.aspx,我怎么能检测Script.aspx,它是从Webpage.aspx称为而不是直接从Web浏览器?

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?

我试过检查的推荐人,但这似乎只返回域,而不是脚本。

我使用ASP.NET Web窗体上的.NET 3.5

推荐答案

在Script.aspx.cs,你可以简单地检查Request的相比,当前的执行路径。

In Script.aspx.cs, you can simply check the Request.Path in comparison 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。因此,如果你在你的Webpage.aspx.cs使用使用Server.Execute后看Request的从你的Script.aspx.cs的价值,你会看到它有/Webpage.aspx的值。

Portions of the request are passed on untouched when you call the Server.Execute. Thus, if you were to look at the value of Request.Path from your Script.aspx.cs after using a Server.Execute in your Webpage.aspx.cs, you will see it has a value of "/Webpage.aspx".

然而,如果网络浏览器是直接访问Script.aspx,Request的从Script.aspx.cs的值将导致/Script.aspx。的currentExecutionPath总是产生当前执行的脚本,因此比较这两种会给期望的结果。

However, if a web browser were to access Script.aspx directly, the value of Request.Path from Script.aspx.cs will result in "/Script.aspx". The currentExecutionPath will always yield the currently executed script, so comparing the two will give the desired result.

希望这有助于。

这篇关于如何检测如果一个aspx页面从使用Server.Execute叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆