Jump to content

Global.asax wont wrok

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Mark4

Mark4

    Newbie

  • Members
  • PipPip
  • 11 posts
Hi good people,

Happy Holiday to you all. Now av got a little problem, my Global.asax file just wont work. I am working with Asp.Net 2.0, IIS 5.1, Win XP Pro. But for no reason the Global.asax wont just work.

I was trying out a hands on exercise on a book. Asp.net Unleashed.

But for no good reason the Global.asax wont work.

The code in Global.asax is below:

<%@ Language="c#" %>

<%@ Import Namespace="System.Data" %>


<script runat=server>


DataTable dtblBannerAds;


public override void Init() {

   DataSet dstBannerAds;


  dstBannerAds = new DataSet();

  dstBannerAds.ReadXml( Server.MapPath( "adFile.xml" ) );

  dtblBannerAds = dstBannerAds.Tables[ 0 ];

}


void Application_PreSendRequestContent(Object sender , EventArgs e) 

 {

   string  strPageFooter;

   Random objRan;

   DataRow drowSelectedAd;


  objRan = new Random();

  drowSelectedAd = dtblBannerAds.Rows[ objRan.Next(dtblBannerAds.Rows.Count)];

  strPageFooter = String.Format("<hr><a href=\"{0}\"><img src=\"{1}\"></a>", drowSelectedAd[ "NavigateUrl" ], drowSelectedAd[ "ImageUrl" ]);

  Response.Write( strPageFooter );

}

</Script>

It has refused to work.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,822 posts
Have you looked at the source code of the page you are receiving? I would think you are attempting to send the footer outside the <HTML> tags.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Mark4

Mark4

    Newbie

  • Members
  • PipPip
  • 11 posts
Thanks for your reply.

This is the source code of the page I receive:

<html>

<head><title>DisplayAd.aspx</title></head>

<body>


<h2>Welcome to our Web site!</h2>

There is no closing </body> tag or closing </html> tag.

Could that have something to do with it?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,822 posts
That just suggests that other pieces of your code aren't taking care of everything they're supposed to. So far, you have two (possibly unrelated) problems with your code. You may need to post the complete code before we can help you adequately.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Mark4

Mark4

    Newbie

  • Members
  • PipPip
  • 11 posts
Thanks for your reply Widget.

Thats all the code there. The page thats suppose to show the adverts called by the Global.asax's call to an xml file known as adFile.xml.

If this code could all be rewritten such that it works, I wont mind I just need a working example with Global.asax, that way am sure its not my computer. Av tried on other PC's though but I get the same result.

Once again thanks.

#6
Mark4

Mark4

    Newbie

  • Members
  • PipPip
  • 11 posts
Attached is the xml file and the gif images.

I so much like Stephen Walther book.

I understand everything quite well until I got to Chapter 15 where this problem of a code is shown as an example.

Attached Files



#7
Mark4

Mark4

    Newbie

  • Members
  • PipPip
  • 11 posts
Going through this website The Global.asax file does not raise events in an ASP.NET 2.0 application I think that is the reason why the Global.asax is not raising events.

Now my other problem is how to revert back to Framework 1.0, just to get my codes runing then I could gradually convert them to 2.0 or 3.5 when am sure they are all runing well and good.

Please help meeeeee

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,822 posts
I don't code in ASP.NET, and you haven't posted the code necessary for any of us to help you. Without your ASPX files, we can't offer you much assistance.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog