Link to home
Start Free TrialLog in
Avatar of HStrix
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
 
Avatar of mmarinov
mmarinov

Hi,
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
Avatar of 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
You can close the Internet Explorer window by putting the snippet  below at the point in your code where processing completes:

    RegisterStartupScript("close","<script 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.
Sorry, missed the closing quote and bracket. Should be:

    RegisterStartupScript("close","<script 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.
Avatar of HStrix

ASKER

Thanks crescendo,
your second comment sounds very good.
Can you supply this VB6 snippet?
Avatar of HStrix

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.



ASKER CERTIFIED SOLUTION
Avatar of crescendo
crescendo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HStrix

ASKER

Thank you very much crescendo,
another idea could be (similar as you suggested):
   RegisterStartupScript("close", "<script Language=JavaScript>  history.back(); </script>")
Yes, that would take you to the previous page in the browser, if one existed. But it wouldn't close the window.
Avatar of HStrix

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.XMLDOM")
    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.