日期:2014-05-18  浏览次数:20378 次

关于aspx访问时 完全输出js 文件
我最近在做一个网站,
希望用户在访问AAA.aspx页面的时候,得到的页面是一个AAA.js文件格式。也就是说AAA.aspx从IE查看源代码的时候看到的是一个js的文件格式。。里面包括很多的js   设置。。。请问如何才能做到。。我看过很多方法都是用response.write   输出。。
但是这种方法只能一句一句的输出。。、
又没有办法输出一个复杂的JS文件格式。。并且又可以通过读取URL   的参数   运算以后在写回前面的js代码里。

------解决方案--------------------


<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "PrintAd.aspx.cs " Inherits= "PrintAd " %>
var adCode= " <%=AdCode%> ";
var outPutStr= " ";
if(adCode== " ")
{
outPutStr= "广告加载出错! ";
document.write(outPutStr);

}
else
{
var numSplit=adCode.lastIndexOf( ". ")+1;
var adType=adCode.substring(numSplit);
switch(adType.toLowerCase())
{
case "gif ":
outPutStr= " <img src=\ " "+adCode+ "\ "/> ";
break;
case "jpg ":
outPutStr= " <img src=\ " "+adCode+ "\ "/> ";
break;
case "swf ":
outPutStr=
' <object classid= "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 " codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0 " width= "1000 " height= "585 "> '
+ ' <param name= "movie " value= " '+adCode+ ' " /> '
+ ' <param name= "quality " value= "high " /> '
+ ' <embed src= "index1.swf " quality= "high " pluginspage= "http://www.macromedia.com/go/getflashplayer " type= "application/x-shockwave-flash " width= "1000 " height= "585 "> </embed> '
+ ' </object> "; '
break;
default:
outPutStr= "广告加载出错! ";
break;
}
document.write(outPutStr);
}


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Gnhao.DataHelper;
using System.Data.SqlClient;

public partial class PrintAd : System.Web.UI.Page
{
DataHelper helper = new DataHelper(DataSource.SqlServer, ConnString.GetConnString());
protected string AdCode= " ";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString[ "AdId "] == null||Request.QueryString[ "WebSite "]==null)
{
AdCode = " ";
return;
}
HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
bc = Request.Browser;
string ip;
string browser;
string platform;
string refUrl;
int CityId;
int adId=2;
int customerId=1;
string language;
string detailPlace;

ip =GetIp();
browser = bc.Type;
platform = bc.Platform;
refUrl = Request.QueryString[ "WebSite "];
CityId = GetCityId(ip);
detailPlace = GetDetailPlace(ip);
language = Request.UserLanguages[0].ToString();
//记录来访信息
RecordVistorInfo(ip, browser, platform, refUrl, CityId,adId,customerId,language,detai