这不起作用:
try
{
EnvironmentVerifier.VerifyAppFoldersAndFiles();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Error!", "alert('" + ex.Message + "');", true);
Logger.LogError(ex.Source, ex.TargetSite.ToString(), ex.Message);
return;
}
发生错误时,它会进入catch块,但警报消息未显示。我错过了什么吗?
答案 0 :(得分:4)
试试这个:
ClientScript.RegisterStartupScript(GetType(), "Error!", "alert('" + ex.Message.Replace("'", @"\'") + "');", true);
.Replace(“'”,@“\'”)会逃脱你的警报('消息');因为如果你有这样的错误信息:
alert('My error message's problem is that single quote.');
除非你这样做否则会破坏:
alert('My error message\'s problem is that single quote.');