tags:

views:

48

answers:

2

I would like to force SSL on certain pages around the site, like for login, registration etc. by specifying a string array and checking whether the current URL fits a certain criteria in a custom HttpModule. It works well, as long as the URL correctly reflects the page, however I use routing tables, so some requests I point to login page, if a page requires login, and I end up with a login page on the screen and with an URL for members' area. Is there a way to find the actual file name of a page?

Example:
http://www.mysite.com/login - file name is login.aspx, which is not reflected by the url. http://www.mysite.com/members - file name is still login.aspx if a user is not logged in.

A: 
 System.IO.Path.GetFileName(HttpContext.Current.Request.FilePath);
Chris McCall
No, because I'm routing tables this only returns path, not actual file name
Shagglez
+1  A: 

Instead of using the URL, could you use the class name?

If TypeOf(Page) Is LoginPage Then

End If 
adam0101
Yes, I can. But if I'm on the page already I might as well get file name (or masterpage, so I don't have to replicate the code). I wanted to do it in HttpModule to speed the process up a bit, as I could trigger redirect at an earlier stage during page life cycle. In addition at the moment all these pages use the same masterpage, but this won't necessarily stay the case.
Shagglez
I would put the code in a base page that's inherited and share the code that way instead of putting it in the master page.
adam0101
Basepage is a better idea, thanks. Marking as Accepted. I ended up using Page.AppRelativeVirtualPath anyway to get the file name, because otherwise I'd need to inherit pages differently.
Shagglez