如何告诉IE忽略以前收到的格式错误的HTML并呈现不同的HTML? [英] How to tell IE to ignore previously received malformed HTML and render different HTML?
问题描述
我们有一个运行.Net 4.0的MVC.Net 2应用程序。在某些情况下,我们的视图中的嵌入代码可能会出错,向浏览器发送格式错误的HTML。
We have an MVC.Net 2 application running with .Net 4.0. There are cases where embedded code in our views may err, sending malformed HTML to the browser.
如何告诉Internet Explorer关闭所有打开的属性和元素,以便它可以正确呈现错误消息?
How can I tell Internet Explorer to close any open attributes and elements so it can properly render an error message?
要捕获并记录嵌入代码中的错误,我将视图的HTML和嵌入代码包含在try-catch的try块中结构,只需要在记录错误后向用户显示一条简单的消息。
To catch and log errors in the embedded code, I'm enclosing the view's HTML and embedded code in the try block of a try-catch structure and just want a simple message displayed to the user after logging the error.
示例:
<%
try {
%>
<div id="div1">
<label class="<%=embedded.code.that.may.err%>">mylabel</label>
<div id="div2" class="data-style">
<%=more.embedded.code.that.may.err%>
</div>
</div>
<%
}
catch(Exception ex) {
(new LogManager()).Save(ex);
%>
<div style="color:red;font-weight:bold;font-size:large;">
Sorry, there was an error.
</div>
<%
}
%>
推荐答案
不要。让您的容易出错的代码运行并将结果放入字符串变量中。把它放在try-catch块中。然后,没有错误你可以写出整个#div1块,包括你已经评估的字符串,知道不会有错误。
Don't. Have your error prone code run and put the result into string variables. Put that in the try-catch block. Then, it there's no error you can write out the entire #div1 block including your already evaluated strings knowing that there won't be an error.
这篇关于如何告诉IE忽略以前收到的格式错误的HTML并呈现不同的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!