HStrix
asked on
Asp.Net: writing a self-terminating web-application
Hello experts,
I'm in need to write an Asp.Net web application (in VB.Net) as follows:
- it can be called only by http://www.xxx.com:<port>
How can I ensure this?
- it writes something to a database (no question)
- it terminates itself
How can I perform this?
If anyone knows a solution please supply appropriate [snippet] information.
Thank you very much!
HStrix
I'm in need to write an Asp.Net web application (in VB.Net) as follows:
- it can be called only by http://www.xxx.com:<port>
How can I ensure this?
- it writes something to a database (no question)
- it terminates itself
How can I perform this?
If anyone knows a solution please supply appropriate [snippet] information.
Thank you very much!
HStrix
ASKER
Thanks mmarinow,
the application for the site exists as IIS web application.
It exists and 'waits' that is will be used (that is current plan).
In normal cases the web application gets activated selecting a URL.
Then you finish the application by (for instance) clicking the X in the top right corner of the Internet Explorer.
For my situation,
I want that the web application gets activated by a sending its URL from a program.
And then - if its function is done - it shall simulate the click on the X or anything else to close the Internet Explorer.
I don't know if this is possible.
Probably I need to write a web service.
But I'm unsure if I have to.
Perhaps I also think not in the right direction,
but the function is as I described.
HStrix
the application for the site exists as IIS web application.
It exists and 'waits' that is will be used (that is current plan).
In normal cases the web application gets activated selecting a URL.
Then you finish the application by (for instance) clicking the X in the top right corner of the Internet Explorer.
For my situation,
I want that the web application gets activated by a sending its URL from a program.
And then - if its function is done - it shall simulate the click on the X or anything else to close the Internet Explorer.
I don't know if this is possible.
Probably I need to write a web service.
But I'm unsure if I have to.
Perhaps I also think not in the right direction,
but the function is as I described.
HStrix
You can close the Internet Explorer window by putting the snippet below at the point in your code where processing completes:
RegisterStartupScript("clo se","<scri pt Language=JavaScript> window.close(); </script>
This will add the javascript to the bottom of the page, so that as the page completes loading, it closes itself.
RegisterStartupScript("clo
This will add the javascript to the bottom of the page, so that as the page completes loading, it closes itself.
Sorry, missed the closing quote and bracket. Should be:
RegisterStartupScript("clo se","<scri pt Language=JavaScript> window.close(); </script>")
However, this will cause a message box "The page you are viewing is trying to close the window" and the user has to click on a button. Is this acceptable?
Another approach would be for the calling program to initiate the program by requesting the URL, waiting for the page to load, scanning the HTML for a particular success or failure message, then ending the session. That's easy enough to do in a program. I've done it before in VB6.
RegisterStartupScript("clo
However, this will cause a message box "The page you are viewing is trying to close the window" and the user has to click on a button. Is this acceptable?
Another approach would be for the calling program to initiate the program by requesting the URL, waiting for the page to load, scanning the HTML for a particular success or failure message, then ending the session. That's easy enough to do in a program. I've done it before in VB6.
ASKER
Thanks crescendo,
your second comment sounds very good.
Can you supply this VB6 snippet?
your second comment sounds very good.
Can you supply this VB6 snippet?
ASKER
==> "However, this will cause a message box "The page you are viewing is trying to close the window" and the user has to click on a button.
Is this acceptable?"
I'ld like to suppress/prevent such a message, because it shall run without any user inter action.
Is this acceptable?"
I'ld like to suppress/prevent such a message, because it shall run without any user inter action.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much crescendo,
another idea could be (similar as you suggested):
RegisterStartupScript("clo se", "<script Language=JavaScript> history.back(); </script>")
another idea could be (similar as you suggested):
RegisterStartupScript("clo
Yes, that would take you to the previous page in the browser, if one existed. But it wouldn't close the window.
ASKER
Hello crescendo,
now my checks are finished.
Based on your code I modified it and got it to work solving my problem.
I needed to replace
Set httpReq = New MSXML2.XMLHTTP40
by
Set httpReq = New MSXML2.ServerXMLHTTP30
In addition, I stripped the line of the asp.net application containing
my indicating field "asp_chk" using InStr commands (simular as you've done)
lPosStart = InStr(sResponse, "<textarea name=""asp_chk""")
tmpString = Mid(sResponse, lPosStart)
and
lPosEnd = InStr(tmpString, "</textarea>")
strTagLine = Mid(tmpString, 1, lPosEnd + Len("</textarea>"))
Then I used the following function to detect the value:
---
Public Function readXmlValue(actXMLString As String) As String
Dim domDoc As MSXML2.DOMDocument
Dim strTagValue As String
Dim strXmlString As String
readXmlValue= ""
Set domDoc = CreateObject("Microsoft.XM LDOM")
domDoc.async = False
strXmlString = "<?xml version=""1.0"" ?><dummy>" & actXMLString & "</dummy>"
domDoc.loadXML (strXmlString)
strTagValue = domDoc.Text
readXmlValue = strTagValue
End Function
---
In the Page_Load event of the asp.net application I inserted:
---
Me.asp_chk.Text = "before"
Call write2file("before") ' this routine writes this line to a local text file
Me.asp_chk.Text = "close me!" ' that is my value indicating the close
Call write2file("after")
---
Again, thank you very much for your help.
HStrix
now my checks are finished.
Based on your code I modified it and got it to work solving my problem.
I needed to replace
Set httpReq = New MSXML2.XMLHTTP40
by
Set httpReq = New MSXML2.ServerXMLHTTP30
In addition, I stripped the line of the asp.net application containing
my indicating field "asp_chk" using InStr commands (simular as you've done)
lPosStart = InStr(sResponse, "<textarea name=""asp_chk""")
tmpString = Mid(sResponse, lPosStart)
and
lPosEnd = InStr(tmpString, "</textarea>")
strTagLine = Mid(tmpString, 1, lPosEnd + Len("</textarea>"))
Then I used the following function to detect the value:
---
Public Function readXmlValue(actXMLString As String) As String
Dim domDoc As MSXML2.DOMDocument
Dim strTagValue As String
Dim strXmlString As String
readXmlValue= ""
Set domDoc = CreateObject("Microsoft.XM
domDoc.async = False
strXmlString = "<?xml version=""1.0"" ?><dummy>" & actXMLString & "</dummy>"
domDoc.loadXML (strXmlString)
strTagValue = domDoc.Text
readXmlValue = strTagValue
End Function
---
In the Page_Load event of the asp.net application I inserted:
---
Me.asp_chk.Text = "before"
Call write2file("before") ' this routine writes this line to a local text file
Me.asp_chk.Text = "close me!" ' that is my value indicating the close
Call write2file("after")
---
Again, thank you very much for your help.
HStrix
Well done for getting it working, and thanks for sharing the finished product, others will find that useful in the future.
for creating a site to a secific port you have to open the IIS and create a new site and set the port to be different than the default 80 port. so when you call the www.xxx.com it will call the default site on your IIS, but if you type the www.xxx.com:yyyy where yyyy is the number of the port than your site will be called up
for the termination - what exactly do you want to perform ? because the site is active (doing something) when you call it, otherwise it is inactive and waintg for calls
Regards,
B..M