Estoy tratando de inyectar js a la página (a etiquetas) usando ihttpmodule. pero js no está inyectado.Inyectar js desde IhttpModule
lo que hice:
la página:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyTempProject._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Temp</title>
</head>
<body>
<form id="form1">
<div>
</div>
</form>
</body>
</html>
la IHttpModule:
public class MyExtensionModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
string script = "/Scripts/jquery-1.5.1.js";
if (page.Header != null)
{
string scriptTag = String.Format("<script language=\"javascript\" type=\"text/javascript\" src=\"{0}\"></script>\n", script); page.Header.Controls.Add(new LiteralControl(scriptTag));
}
else if (!page.ClientScript.IsClientScriptIncludeRegistered(page.GetType(), script)) page.ClientScript.RegisterClientScriptInclude(page.GetType(), script, script);
}
}
#endregion
}
bueno, nunca va a ser agregado a la página. Cabezal porque eso no existe (basado en tu código). ¿Se está produciendo algo? ¿Has recorrido el código? ¿Estás recibiendo alguna excepción? – jonezy
no, no hay ninguna excepción ... nunca se agrega la etiqueta ... así que ¿cómo puedo agregar etiquetas a la cabeza? ¿Tienes alguna idea? –