2

I have a webpage I am working on using asp.net mvc3. I am deploying it via appharbor which is amazing. The entire page is public, so I don't need user authentication or anything like that, but there are administrative pages that only I should be able to access.

Rather than have any kind of authentication page with a password, I would like certain views to be only accessible while I am running it locally in debug mode, but not once I have deployed to appharbor.

Is there some kind of environment setting that I can use to:

  1. Show or hide page elements (links) based on whether it is running locally or on the server.
  2. Restrict access to entire views (return 403) if the application is running on appharbor.

How would I read and apply these settings in my views and controllers?

4

2 回答 2

2

A crude way would be to use

#if DEBUG
    ... some code here
#else
    ... some other code here
#end if

as : http://haacked.com/archive/2007/09/16/conditional-compilation-constants-and-asp.net.aspx#51205

and Is there an #IF DEBUG for Asp.net markup?

于 2011-06-05T06:41:06.980 回答
1

AppHarbor now supports web.config transformations so in your release or AppHarbor web.config you could block those files or a folder in the web.config.

于 2011-06-05T06:44:44.383 回答