我使用以下代码清理Azure App的数据库。
protected void Application_End(object sender, EventArgs e)
{
core.cleanUpDB();
}
我可以在调试时阻止在本地计算机上执行此操作吗?我只想在部署的Azure应用程序上执行此操作。
提前致谢。
答案 0 :(得分:5)
您可以使用HttpRequest.IsLocal来区分本地和服务器请求。
protected void Application_End(object sender, EventArgs e)
{
if(!System.Web.HttpContext.Current.Request.IsLocal)
core.cleanUpDB();
}
答案 1 :(得分:4)
虽然其他答案可能在特定方案中有效,但它们与Windows Azure无关。检查您是否在Windows Azure中运行而不是在模拟器中运行(假设您具有Web角色)的唯一方法是这样的:
protected void Application_End(object sender, EventArgs e)
{
if (RoleEnvironment.IsAvailable && !RoleEnvironment.IsEmulated)
core.cleanUpDB();
}
答案 2 :(得分:1)
您使用conditional compilation。 MSDN文章提供了一个更好的解释,我可以在这里的小空间写。
答案 3 :(得分:0)
'#If DEBUG Then
'only do this while debugging...
'#End If
请删除'mark - stack overflow使用“#”标记为BOLD .... 我认为它也应该在C#中编译。