Guest User

Untitled

a guest
Aug 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. How can I inject a piece of VB.NET code in to an ASPX page and have it execute?
  2. <script type="text/javascript">
  3.  
  4. (function() {
  5.  
  6. if (someCondition) {
  7. if (<%=MyObject.IsActiveSession.ToString().ToLower() %>) {
  8. <% If (MyObject.IsLoggedIn) Then %>
  9. // Do some fancy stuff
  10. <% End If %>
  11. }
  12. }
  13. })();
  14. </script>
  15.  
  16. <script type="text/javascript">
  17.  
  18. (function() {
  19.  
  20. if (someCondition) {
  21. if (<%=MyObject.IsActiveSession.ToString().ToLower() %>) {
  22. <% If (MyObject.IsLoggedIn) Then %>
  23. // Do some fancy stuff
  24. <% End If %>
  25. }
  26. }
  27. })();
  28. </script>
  29.  
  30. Imports System
  31. Imports System.Collections.Generic
  32. Imports System.IO
  33. Imports System.Linq
  34. Imports System.Web
  35.  
  36. Namespace TestApp1
  37. Public Class TemplateRenderer
  38. Implements IHttpHandler
  39. Private Function GetContent(context As HttpContext, tempateName As String) As String
  40. Using textWriter = New StringWriter()
  41. context.Server.Execute(String.Format("~/Templates/{0}", tempateName), textWriter)
  42. Return textWriter.ToString()
  43. End Using
  44. End Function
  45.  
  46. Public Sub ProcessRequest(context As HttpContext)
  47. context.Response.Write(GetContent(context, context.Request.QueryString("template")))
  48. End Sub
  49.  
  50. Public ReadOnly Property IsReusable() As Boolean
  51. Get
  52. Return False
  53. End Get
  54. End Property
  55. End Class
  56. End Namespace
  57.  
  58. Protected Sub Page_Load(sender As Object, e As EventArgs)
  59. Dim templateName = "LoggedInBlock.aspx"
  60. Using textWriter = New StringWriter()
  61. Server.Execute(String.Format("~/TemplateRenderer.ashx?template={0}", templateName), textWriter)
  62. dynamicCodeInjectPanel.InnerHtml = textWriter.ToString()
  63. End Using
  64. End Sub
Add Comment
Please, Sign In to add comment