Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Saturday, March 31, 2012

server side includes in .net

I'm having a hard time figuring out the .net way to emulate server side includes. I'm aware of the fact that you need to work with user controls via .ascx files. This works fine for me as long as my included file (.ascx) is straight html. My problem I assume is in my page directives. I have an index.aspx page, a index.vb code-behind page, and a header.ascx page. Here's what I have:

index.aspx - top of page:
<%@dotnet.itags.org. Page language="vb" Inherits="index" src="http://pics.10026.com/?src=index.vb" %>
<%@dotnet.itags.org. Register TagPrefix="uctl1" TagName="header" src="http://pics.10026.com/?src=includes\header.ascx" %>
index.aspx -body:
<uctl1:header runat="server" /
header.ascx - top of page:
<%@dotnet.itags.org. Control Language="VB" EnableViewState="False" %>
header.ascx - body:
<asp:label id="todaysDate" runat="server" /
index.vb - top of page:
nothing (as far as page directives go. I am importing appropriate vb classes, fyi)
code that pertains to date calc:

protected withEvents lblTodaysDate as label

Sub Page_Load ( s as Object, e as EventArgs )
Dim currentDate as DateTime
currentDate=DateTime.Now
lblTodaysDate.text=currentDate.AddHours(3).toString("MMMM d")

End Sub

my errors pertain to the header & code-behind pages not recognizing one another as far as the date label go. Should i be inheriting one page from the other or something?You need to make the todaysDate label public or provide access to it through a public property. See this article:

http://aspalliance.com/articleViewer.aspx?aId=67&pId=-1
It's not your page that should have this codebehind, it's your user control.
Remove the src of your page (except if you intend to put some code there later) and transfer your codebehind to header.ascx.vb. Set the src attribute of your <%@. Control %> directive to header.ascx.vb.
Finally, give the label the same ID that you have in the ascx file (and not todaysDate in one and lblTodaysDate in the other).

Monday, March 26, 2012

server to server post ??

I'm not even sure if the title of my post is correct but here's what i'm trying to do.

trying to via asp.net 2.0 code, send a request directly to a web site with a formatted querystring.

how do i do this?

I don't know about others, but I'll need a little more information - -

normally a querystring would be something like:
http://TheWebsite.com?id=myID

It all depends on where it's coming from and exactly what you want to do.
You can create a Hyperlink on a page (either HTML or ASP.Net) with a hard coded url/querystring
You can create an ASP.Net Hyperlink on a page, and, based on input somewhere else on your page, make the web address and/or querystring dynamic, based on the other data.

What are you looking to do, exactly?


I'm trying to send data to a public server ... like a city directory search using the querystring... and then save the data to an excel spreadsheet.

so far, i've been able to use httpwebrequest / httpwebresponse to do this.. but the response is really ugly. i get all the hml ... i'm only interested in the actual data... and it's kinda tricky cause if the search returns multiple pages, then it looks like i'm going to have to search through the response text to find the session id and then post over and over again until all data is retrieved.

... any comments? does this sound reasonable?


What I have understood from your query is you want some response from some public website from your web server & want to show the information on your page. As per my understanding you need to use httpwebresponse & search through the response text.

If you can use web service rather then website from your page, it would resolve your problem. In that case you will be having result rather then web reponse. But for that web service shoudl be provided by the called public server.

Saturday, March 24, 2012

Server Up/Down via TCP

I am trying to do a server status page. I am having an issue with getting mulitple servers to show status. I have one that replies and that is it. I am using Visual Studio 2005 with VB. I am using the following:

Imports System.IO
Imports System.Drawing
Imports System.Net
Imports System.Net.Sockets

Dim xxxxx as string = " ipaddress"

Dim tcpClient As New Tcpclient

Dim myxxx as ipaddress - ipaddress.parse(XXXX)

then I do a

Try
tcpClient.COnnect(myXXXX, 80)
xxxxtxt.text = "ONLINE"
xxxxtxt.forecolor = system.drawing.color.green
Catch ex As Exception
xxxxtxt.text = "OFFLINE"
xxxxtxt.forecolor = system.drawing.color.red
End Try

Like I said I can only get this to work for one and not the others. Any help would be greatly appreciate. I am open to doing this another way if anyone has one.


Hello,

You could write some code(object) to call WMI and it can show your server status. Follow this example, you will solve your problem.

Listening for WMI Events in ASP.NET Health Monitoring

http://msdn2.microsoft.com/en-us/library/ms178713%28VS.80%29.aspx

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.
In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.
This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and th
e
code worked fine on our test environment again.
-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);
Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.
The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.
"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in messa
ge
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> and
> an
> reboot
> commented
> the
>
>

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.

In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.

This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and the
code worked fine on our test environment again.

-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);

Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.

The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.

"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> > We have a page which sends a copy of itself via email to customers. To
> > enable this, the page calls Server.Execute on itself into a text stream
> and
> > strips its own output down to HTML presentable to the customer.
> > In our Test environment (but not our DEV or Local envs) we are experience
> an
> > ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
> reboot
> > the server before any of our other ASP.NET apps will work.
> > This is a sample of the code which appears to be the culprit. We
> commented
> > out the Server.Execute and substituted some junk text to build sbText and
> the
> > code worked fine on our test environment again.
> > -- Locks server
> > StringBuilder sb = new StringBuilder();
> > sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> > sb.Append(erNumber);
> > System.IO.TextWriter textwriter = new System.IO.StringWriter();
> > StringBuilder sbText = new StringBuilder(textwriter.ToString());
> > Server.Execute(sb.ToString(), textwriter);
> > Is there any known issue with Server.Execute on itself?
>

Thursday, March 22, 2012

Server.GetLastError

Hello,
I am trying to get the last occured error via the
following code:
Sub Page_Load(...)
Dim zero As Integer = 0
Try
Dim err As Integer = 10 / zero
Catch ex As Exception
End Try
Response.write(Server.GetLastError.Message)
End Sub
However the above code always throws an error at the
response.write line with:
Object reference not set to an instance of an object.
Anybody knows why this is happening?Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.
I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request
Example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub
Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub
Or since it's now available anywhere, you could also do something like this:
Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub
And then in error.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub
"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Since you are catching the exception, it is no longer an error.
bill
"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Hello VK,
If this code would generate an error (which it wont as detailed by Brad),
you're swallowing it anyways. You need to remove the try/catch.
Matt Berther
http://www.mattberther.com

> Hello,
> I am trying to get the last occured error via the following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the response.write
> line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
>

Server.GetLastError

Hello,

I am trying to get the last occured error via the
following code:

Sub Page_Load(...)
Dim zero As Integer = 0
Try
Dim err As Integer = 10 / zero
Catch ex As Exception
End Try

Response.write(Server.GetLastError.Message)
End Sub

However the above code always throws an error at the
response.write line with:

Object reference not set to an instance of an object.

Anybody knows why this is happening?Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.

I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request

Example:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub

Or since it's now available anywhere, you could also do something like this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub

And then in error.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Well, first off 10/0 will not throw an error. I also assume you must have
Option Strict Off or your code would not even compile: err would need to be
dimmed as a double or you would need ctype(10/zero, double) for code to
compile.

I think GetLastError only returns the last unhandled error, during the
current context, and I think the page's Page_Error event or global.asax
Application_Error event has to be raised to access it. Once one of those
events is raised Server.GetLastError is available anywhere in your
code...for the remainder of the current context / request

Example:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim zero As Integer = 0
Dim err As Double = 10 / CType("x", Integer)
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Response.Write(Server.GetLastError.Message)
End Sub

Or since it's now available anywhere, you could also do something like this:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Server.Transfer("error.aspx")
End Sub

And then in error.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Server.GetLastError.Message)
End Sub

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Since you are catching the exception, it is no longer an error.

bill

"VK" <anonymous@.discussions.microsoft.com> wrote in message
news:0dfb01c54132$353bf820$a401280a@.phx.gbl...
> Hello,
> I am trying to get the last occured error via the
> following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the
> response.write line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?
Hello VK,

If this code would generate an error (which it wont as detailed by Brad),
you're swallowing it anyways. You need to remove the try/catch.

--
Matt Berther
http://www.mattberther.com

> Hello,
> I am trying to get the last occured error via the following code:
> Sub Page_Load(...)
> Dim zero As Integer = 0
> Try
> Dim err As Integer = 10 / zero
> Catch ex As Exception
> End Try
> Response.write(Server.GetLastError.Message)
> End Sub
> However the above code always throws an error at the response.write
> line with:
> Object reference not set to an instance of an object.
> Anybody knows why this is happening?