4
A
回答
5
爲客戶端
在Internet Explorer
右鍵單擊瀏覽器 - >查看源代碼
在Firefox
右鍵單擊瀏覽器 - >查看頁面來源
服務器端
您可以覆蓋頁面的呈現方法來捕獲服務器端的HTML源代碼。
protected override void Render(HtmlTextWriter writer)
{
// setup a TextWriter to capture the markup
TextWriter tw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(tw);
// render the markup into our surrogate TextWriter
base.Render(htw);
// get the captured markup as a string
string pageSource = tw.ToString();
// render the markup into the output stream verbatim
writer.Write(pageSource);
// remove the viewstate field from the captured markup
string viewStateRemoved = Regex.Replace(pageSource,
"<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\".*?\" />",
"", RegexOptions.IgnoreCase);
// the page source, without the viewstate field, is in viewStateRemoved
// do what you like with it
}
2
重寫渲染方法並使用自己的HtmlWriter調用base.Render。
+0
有沒有辦法使用Request.Url獲取當前頁面的html? – Constantine 2009-10-21 11:51:47
+0
什麼意思是「使用Request.Url的當前頁面」? – 2009-10-21 12:35:43
1
相關問題
- 1. 在HTML上獲取當前頁面
- 2. 如何獲取當前頁面的ID
- 3. 獲取當前頁面(PHP)
- 4. JSF獲取當前頁面
- 5. 如何獲取當前頁面的「頁面類型」。 EPiServer
- 6. 如何從asp.net獲取當前頁面源代碼頁面
- 7. 獲取當前頁面的子頁面以及當前頁面鏈接
- 8. 如何獲取當前頁面的php/mysql分頁
- 9. Kaminari分頁,如何獲取當前頁面的編號?
- 10. 獲取FlowDocumentPageViewer的當前頁面
- 11. 獲取鉤子的當前頁面ID
- 12. 從WebView獲取當前頁面的URL
- 13. 如何獲取當前html的路徑?
- 14. 從Chrome擴展中獲取當前頁面的源HTML
- 15. modx php獲取當前頁面名稱
- 16. CakePHP PaginatorHelper:獲取當前頁面
- 17. 用JSP獲取當前頁面節點
- 18. 獲取當前頁面編程
- 19. 用C獲取當前頁面#
- 20. Umbraco.TagQuery從當前頁面獲取標籤
- 21. 從url獲取當前頁面
- 22. 如何獲取html頁面的標題
- 23. 如何訪問當前[網頁]頁面(當前頁面之外)?
- 24. 如何從Controller插件中的Zend_Navigation獲取當前頁面
- 25. 如何從ASP.NET頁面獲取當前登錄的Windows帳戶?
- 26. 瀏覽器擴展 - 如何獲取當前頁面的URL
- 27. 如何獲取GAE模板中當前頁面的網址
- 28. 如何在Laravel 5中獲取當前頁面的細分?
- 29. 如何獲取請求庫中的當前頁面URL?
- 30. asp.net Server.Transfer之後如何獲取當前頁面的路徑?
你錯過了服務器客戶端 - 第二次運行時包含HttpRequest和HttpResponse – cjk 2009-10-19 12:39:52
:) – solairaja 2009-10-19 12:48:03