Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can I inject a piece of VB.NET code in to an ASPX page and have it execute?
- <script type="text/javascript">
- (function() {
- if (someCondition) {
- if (<%=MyObject.IsActiveSession.ToString().ToLower() %>) {
- <% If (MyObject.IsLoggedIn) Then %>
- // Do some fancy stuff
- <% End If %>
- }
- }
- })();
- </script>
- <script type="text/javascript">
- (function() {
- if (someCondition) {
- if (<%=MyObject.IsActiveSession.ToString().ToLower() %>) {
- <% If (MyObject.IsLoggedIn) Then %>
- // Do some fancy stuff
- <% End If %>
- }
- }
- })();
- </script>
- Imports System
- Imports System.Collections.Generic
- Imports System.IO
- Imports System.Linq
- Imports System.Web
- Namespace TestApp1
- Public Class TemplateRenderer
- Implements IHttpHandler
- Private Function GetContent(context As HttpContext, tempateName As String) As String
- Using textWriter = New StringWriter()
- context.Server.Execute(String.Format("~/Templates/{0}", tempateName), textWriter)
- Return textWriter.ToString()
- End Using
- End Function
- Public Sub ProcessRequest(context As HttpContext)
- context.Response.Write(GetContent(context, context.Request.QueryString("template")))
- End Sub
- Public ReadOnly Property IsReusable() As Boolean
- Get
- Return False
- End Get
- End Property
- End Class
- End Namespace
- Protected Sub Page_Load(sender As Object, e As EventArgs)
- Dim templateName = "LoggedInBlock.aspx"
- Using textWriter = New StringWriter()
- Server.Execute(String.Format("~/TemplateRenderer.ashx?template={0}", templateName), textWriter)
- dynamicCodeInjectPanel.InnerHtml = textWriter.ToString()
- End Using
- End Sub
Add Comment
Please, Sign In to add comment