How to tell IE to ignore previously received malformed HTML and render different HTML?

女生的网名这么多〃 提交于 2019-12-11 15:59:57

问题


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.

How can I tell Internet Explorer to close any open attributes and elements so it can properly render an error message?

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.

Example:

<%
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>
<%
}
%>

回答1:


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.



来源:https://stackoverflow.com/questions/15577463/how-to-tell-ie-to-ignore-previously-received-malformed-html-and-render-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!