搜尋
首頁web前端html教學Tailspin Spyworks指南第八讲:其它页面,异常处理、总结_html/css_WEB-ITnose

Part 8: Final Pages, Exception Handling, and Conclusion 其它页面、异常处理、总结

By  Joe Stagner |July 21, 2010

Print

Tailspin Spyworks demonstrates how extraordinarily simple it is to create powerful, scalable applications for the .NET platform. It shows off how to use the great new features in ASP.NET 4 to build an online store, including shopping, checkout, and administration.

通过Tailspin Spyworks 演示在.NET平台创建功能强大,结构良好的应用程序有多么简单。演示如何使用ASP.NET 4的新特性创建一个包含购物、结算和管理功能的在线网店。

This tutorial series details all of the steps taken to build the Tailspin Spyworks sample application.  Part 8 adds a contact page, about page, and exception handling.  This is the conclusion of the series.

本系列指南对构建案例程序的每一步做了详细的解释。第八部分添加联系页面、关于页面和异常处理,也是对整个系列的总结。

联系页面(从Asp.net发送Email)

Create a new page named ContactUs.aspx
创建名为ContactUs.aspx的页面

Using the designer, create the following form taking special note to include the ToolkitScriptManager and the Editor control from the AjaxdControlToolkit. .
使用Ajax控件包设计如下页面:

Double click on the "Submit" button to generate a click event handler in the code behind file and implement a method to send the contact information as an email.
双击“提交”按钮,生成点击事件处理函数,在其中完成发送email的功能。

protected void ImageButton_Submit_Click(object sender, ImageClickEventArgs e)  {  try     {    MailMessage mMailMessage = new MailMessage();    mMailMessage.From = new MailAddress(HttpUtility.HtmlEncode(TextBoxEmail.Text));    mMailMessage.To.Add(new MailAddress("Your Email Here"));     // mMailMessage.Bcc.Add(new MailAddress(bcc));    // mMailMessage.CC.Add(new MailAddress(cc));   mMailMessage.Subject = "From:" + HttpUtility.HtmlEncode(TextBoxYourName.Text) + "-" +                                     HttpUtility.HtmlEncode(TextBoxSubject.Text);   mMailMessage.Body = HttpUtility.HtmlEncode(EditorEmailMessageBody.Content);    mMailMessage.IsBodyHtml = true;   mMailMessage.Priority = MailPriority.Normal;   SmtpClient mSmtpClient = new SmtpClient();   mSmtpClient.Send(mMailMessage);   LabelMessage.Text = "Thank You - Your Message was sent.";   } catch (Exception exp)   {   throw new Exception("ERROR: Unable to Send Contact - " + exp.Message.ToString(), exp);   }}

This code requires that your web.config file contain an entry in the configuration section that specifies the SMTP server to use for sending mail.
此代码需要在Web.config文件中包含指明配置,在配置中设置发送邮件使用的SMTP服务器。

    <system.net>        <mailSettings>            <smtp>                <network                     host="mail..com"                     port="25"                     userName=""                     password="" />            </smtp>        </mailSettings>    </system.net>

关于页面

Create a page named AboutUs.aspx and add whatever content you like.
创建名为AboutUs.aspx的页面,添加你想添加的任何内容。

全局异常处理

Lastly, throughout the application we have thrown exceptions and there are unforeseen circumstances that cold also cause unhandled exceptions in our web application.
在程序中会出现无法预期的异常,需要添加异常处理。

We never want an unhandled exception to be displayed to a web site visitor.
我们绝不希望网站访问者看到这样的异常信息:

Apart from being a terrible user experience unhandled exceptions can also be a security problem.
抛开这将是很恐怖的用户体验不说,还会带来安全问题。

To solve this problem we will implement a global exception handler.
为了解决这个问题,我们将实现一个全局异常处理器。

To do this, open the Global.asax file and note the following pre-generated event handler.
打开Global.asax文件,注意如下自动生成的代码:

void Application_Error(object sender, EventArgs e)     {     // Code that runs when an unhandled error occurs     }

Add code to implement the Application_Error handler as follows.
添加如下代码:

void Application_Error(object sender, EventArgs e)     {     Exception myEx =  Server.GetLastError();    String RedirectUrlString = "~/Error.aspx?InnerErr=" +            myEx.InnerException.Message.ToString() + "&Err=" + myEx.Message.ToString();     Response.Redirect(RedirectUrlString);     }

Then add a page named Error.aspx to the solution and add this markup snippet.
添加名为Error.aspx的页面,添加如下标记:

<center>  <div class="ContentHead">ERROR</div><br /><br />  <asp:Label ID="Label_ErrorFrom" runat="server" Text="Label"></asp:Label><br /><br />  <asp:Label ID="Label_ErrorMessage" runat="server" Text="Label"></asp:Label><br /><br /></center>

Now in the Page_Load event handler extract the error messages from the Request Object.
在Page_Load事件处理器实现现实错误信息。

protected void Page_Load(object sender, EventArgs e){    Label_ErrorFrom.Text = Request["Err"].ToString();    Label_ErrorMessage.Text = Request["InnerErr"].ToString();}

总结

We've seen that that ASP.NET WebForms makes it easy to create a sophisticated website with database access, membership, AJAX, etc. pretty quickly.

Hopefully this tutorial has given you the tools you need to get started building your own ASP.NET WebForms applications!
通过此指南可以看出使用ASP.NET创建一个包含数据访问、成员机制、AJAX等功能的复杂的站点是多么的简单。希望此指南对你有所帮助!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
HTML標籤的目的是什麼?HTML標籤的目的是什麼?Apr 28, 2025 am 12:02 AM

htmltagsareessentialforsenteringwebpages,增強輔助性,seo,and Performance.1)他們areAnclosedInanglebracketSandInpairStocrateAteAhierArchical.2)samantictagsictagsagtagslikleicereperreveuseerexperienceandseo.3)

什麼是自我關閉標籤?舉一個例子。什麼是自我關閉標籤?舉一個例子。Apr 27, 2025 am 12:04 AM

self-closingtagsinhtmlandxmlaretagsthatclosethem hexptneedneedingAseparateClosingTag,SightifyingmarkupStrupupStrupureAndenHancingCodingsigy.1)shemesessientInsentialInxmlforelementswithcontentsswithcontent content content content content content content content content contentcontent,確保wellwell-formedDocuments.2)Inhtmlible5,inhtmlibut forfix

超越HTML:網絡開發的基本技術超越HTML:網絡開發的基本技術Apr 26, 2025 am 12:04 AM

要構建一個功能強大且用戶體驗良好的網站,僅靠HTML是不夠的,還需要以下技術:JavaScript賦予網頁動態和交互性,通過操作DOM實現實時變化。 CSS負責網頁的樣式和佈局,提升美觀度和用戶體驗。現代框架和庫如React、Vue.js和Angular,提高開發效率和代碼組織結構。

HTML中的布爾屬性是什麼?舉一些例子。HTML中的布爾屬性是什麼?舉一些例子。Apr 25, 2025 am 12:01 AM

布爾屬性是HTML中的特殊屬性,不需要值即可激活。 1.布爾屬性通過存在與否控制元素行為,如disabled禁用輸入框。 2.它們的工作原理是瀏覽器解析時根據屬性的存在改變元素行為。 3.基本用法是直接添加屬性,高級用法可通過JavaScript動態控制。 4.常見錯誤是誤以為需要設置值,正確寫法應簡潔。 5.最佳實踐是保持代碼簡潔,合理使用布爾屬性以優化網頁性能和用戶體驗。

如何驗證您的HTML代碼?如何驗證您的HTML代碼?Apr 24, 2025 am 12:04 AM

HTML代碼可以通過在線驗證器、集成工具和自動化流程來確保其清潔度。 1)使用W3CMarkupValidationService在線驗證HTML代碼。 2)在VisualStudioCode中安裝並配置HTMLHint擴展進行實時驗證。 3)利用HTMLTidy在構建流程中自動驗證和清理HTML文件。

HTML與CSS和JavaScript:比較Web技術HTML與CSS和JavaScript:比較Web技術Apr 23, 2025 am 12:05 AM

HTML、CSS和JavaScript是構建現代網頁的核心技術:1.HTML定義網頁結構,2.CSS負責網頁外觀,3.JavaScript提供網頁動態和交互性,它們共同作用,打造出用戶體驗良好的網站。

HTML作為標記語言:其功能和目的HTML作為標記語言:其功能和目的Apr 22, 2025 am 12:02 AM

HTML的功能是定義網頁的結構和內容,其目的在於提供一種標準化的方式來展示信息。 1)HTML通過標籤和屬性組織網頁的各個部分,如標題和段落。 2)它支持內容與表現分離,提升維護效率。 3)HTML具有可擴展性,允許自定義標籤增強SEO。

HTML,CSS和JavaScript的未來:網絡開發趨勢HTML,CSS和JavaScript的未來:網絡開發趨勢Apr 19, 2025 am 12:02 AM

HTML的未來趨勢是語義化和Web組件,CSS的未來趨勢是CSS-in-JS和CSSHoudini,JavaScript的未來趨勢是WebAssembly和Serverless。 1.HTML的語義化提高可訪問性和SEO效果,Web組件提升開發效率但需注意瀏覽器兼容性。 2.CSS-in-JS增強樣式管理靈活性但可能增大文件體積,CSSHoudini允許直接操作CSS渲染。 3.WebAssembly優化瀏覽器應用性能但學習曲線陡,Serverless簡化開發但需優化冷啟動問題。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)