0

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?

Mafti
  • 675
  • 2
  • 11
  • 28

2 Answers2

2

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

if (Page is FooBar) { ... }
leppie
  • 115,091
  • 17
  • 196
  • 297
1

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?

Oli
  • 235,628
  • 64
  • 220
  • 299
  • Or System.IO.Path.GetFileName(HttpContext.Current.Request.FilePath) if you just want the filename – Oli Oct 02 '08 at 08:51