开发者

Restrict access to views to debug only

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 r开发者_开发百科unning 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?


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜