Page.Tostring() 在 .net 1.1 中的行为有点奇怪?

发布于 2024-07-05 20:00:17 字数 373 浏览 7 评论 0原文

我有一个控件,我必须在其中检查我所在的页面,因此我可以相应地设置某个变量。

string pageName = this.Page.ToString();
switch (pageName)
{
case "ASP.foo_bar_aspx": doSomething(); break;
default: doSomethingElse(); break;
}

这在本地和某些开发服务器上运行良好,但是当我将其投入使用时,它停止工作,因为我没有得到 ASP.foo_bar_aspx 而是 _ASP.foo_bar_aspx (注意实时版本中的下划线) 为什么会这样,我可以以某种方式设置它吗?

I have a control where I have to check in which page I am, so I can set a certain variable accordingly.

string pageName = this.Page.ToString();
switch (pageName)
{
case "ASP.foo_bar_aspx": doSomething(); break;
default: doSomethingElse(); break;
}

this works fine locally and on some developmentservers, however when I put it live, It stopped working because I don't get ASP.foo_bar_aspx but _ASP.foo_bar_aspx
(notice the underscore in the live version)
Why does it act that way, Can I set it somehow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白芷 2024-07-12 20:00:17

您不能依赖自动生成的名称。 使用类型代替,例如:

if (Page is FooBar) { ... }

You cant rely on auto generated names. Use types instead, eg:

if (Page is FooBar) { ... }
丘比特射中我 2024-07-12 20:00:17

这似乎是获取当前请求的一种非常狡猾的方式。 您是否尝试过使用 HttpContext.Current.Request.FilePath 或另一个 HttpContext.Current.Request... 变量?

That seems like a really dodgy way of getting the current request. Have you tried using HttpContext.Current.Request.FilePath or another HttpContext.Current.Request... variable instead?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文