简体   繁体   中英

How to run aspx.cs file immediately on url load

sorry I am not exactly sure how to ask this question.

What I am trying to do is create a web service that when the url is hit (a .swf file will send the request and send information) the web service send an email.

So basically if a browser hits a url, say mywebsite.com/smtp/ it loads a aspx.cs file that sends an email. I do not want to have to have the browser open mywebsite.com/smtp/sendemail.aspx.

Basically I just want to be able to run a .cs file on my webserver by just hitting the link.

I assume I just need a bit of code in the .aspx file to immediately load the aspx.cs file.

Any thoughts or help? Sorry I did research I am just not sure how to phrase the question in google.

There are many ways of doing that. The easiest I think would be an HTTPHandler.

http://support.microsoft.com/kb/308001

First I suggest you to use one handler for that (ends with .ashx)

Now, there is not such a think like the cs runs first, the aspx second. There is a full page that runs, do some stuff (one can be the send of an email), renders and return an html page.

In that part you can simple cancel the return of the html by sending the no content as:

Response.TrySkipIisCustomErrors = true;
Response.Status = "204 No Content";
Response.StatusCode = 204;

and end the page cycle with the Response.End(); , or use a handler as I say you that you do not need that.

If I understand the question, you can do this just by setting a default page on that directory (in the IIS settings). So you would set sendemail.aspx as the default page in the smtp virtual directory, and requests for /smtp/ would be handled by sendemail.aspx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM