Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

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
 
0
HStrix
Asked:
HStrix
1 Solution
 
mmarinovCommented:
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
0
 
HStrixAuthor Commented:
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
0
 
crescendoCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
crescendoCommented:
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.
0
 
HStrixAuthor Commented:
Thanks crescendo,
your second comment sounds very good.
Can you supply this VB6 snippet?
0
 
HStrixAuthor Commented:
==> "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.



0
 
AerosSagaCommented:
0
 
crescendoCommented:
Here's the VB6 code. You need to install MSXML2 (get it from MS) for it work. Basically the code below sends a request with some querystring parameters to a web page, gets the returned HTML and looks for some text inside <P> </P> tags. I'm sure you can modify it to suit your needs.

Public Function Register() As Boolean
    Dim httpReq As MSXML2.XMLHTTP40
    Dim sURL As String
    Dim sStatus As String
    Dim lStart As Long
   
    On Error GoTo RegErr
   
    Register = False
    sErrorString = ""
    sComputer = ComputerName
   
    Set httpReq = New MSXML2.XMLHTTP40
   
    sURL = "http://www.yourdomain.com/somepage.aspx" & _
           "?ProductKey=" & sProductKey & _
           "&Computer=" & sComputer

    httpReq.Open "GET", sURL, False
    httpReq.send
   
    lStart = 1
   
    ' See if it was successful
   
    sStatus = GetReplyString(httpReq.responseText, lStart)
   
    If sStatus = "SUCCESS" Then
        sLicenseString = GetReplyString(httpReq.responseText, lStart)
    ElseIf sStatus = "ERROR" Then
        sStatus = GetReplyString(httpReq.responseText, lStart)
        Err.Raise vbObjectError + 1024, "Registration", sStatus
    Else
        Err.Raise vbObjectError + 1024, "Registration", "Reason unknown"
    End If
   
    Register = True
   
RegExit:
    Set httpReq = Nothing
    Exit Function
RegErr:
    sErrorString = Err.Description
    Resume RegExit
End Function

Private Function GetReplyString(sResponse As String, lStart As Long) As String
    Dim lPosStart As Long
    Dim lPosEnd As Long
   
    lPosStart = InStr(lStart, sResponse, "<p>", vbTextCompare)
   
    If lPosStart = 0 Then
        GetReplyString = ""
        lStart = Len(sResponse)
        Exit Function
    End If
   
    lPosEnd = InStr(lPosStart + 3, sResponse, "</p>", vbTextCompare)
   
    If lPosEnd = 0 Then
        GetReplyString = ""
        lStart = Len(sResponse)
        Exit Function
    End If
   
    GetReplyString = Mid(sResponse, lPosStart + 3, lPosEnd - lPosStart - 3)
   
    lStart = lPosEnd + 4
   
End Function
0
 
HStrixAuthor Commented:
Thank you very much crescendo,
another idea could be (similar as you suggested):
   RegisterStartupScript("close", "<script Language=JavaScript>  history.back(); </script>")
0
 
crescendoCommented:
Yes, that would take you to the previous page in the browser, if one existed. But it wouldn't close the window.
0
 
HStrixAuthor Commented:
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

0
 
crescendoCommented:
Well done for getting it working, and thanks for sharing the finished product, others will find that useful in the future.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now