Asp.net and ASP session sharing and ASP Request Interception

Source: Internet
Author: User
Tags allkeys

Asp.net and ASP sessions cannot be directly shared (the underlying processing DLL is different). To connect sessions, you can only use a work und:

I. Asp.net-> Asp session Transfer

A)Create a page similar to sessionhanler. asp,CodeAs follows:

 
<! -- # Include virtual = "INC/func. ASP "--> <% dim returnurl SESSION (" user ") = request (" user ") set returnurl = request (" returnurl ") if returnurl = "" Then returnurl = "home. ASP "end if 'Log appendfile"/log/log.txt ", now () &", user: "& SESSION (" user ") &", returnurl: "& returnurl response. redirect (returnurl) %>

The general function is to receive parameters, generate sessions as needed, and redirect to the real function page, so that other pages have a value when accessing the session.

B)Create an Asp.net page and submit the value to be passed to sessionhanler. asp (either post or get) as a parameter. Refer to the Code:

Using system; namespace asp_aspx_test {public partial class index: system. web. UI. page {protected void page_load (Object sender, eventargs e) {If (ispostback) {string returnurl = "home. ASP "; string sessoinhandlerurl =" sessionhandler. ASP "; string postdata =" user = "+ this.txt user. text + "& returnurl =" + returnurl; response. redirect (sessoinhandlerurl + "? "+ Postdata );}}}}

Ii. asp-> Asp.net session Transfer

In turn, the principle is the same.

3. Intercept ASP requests

For an existing ASP project, do not modify its ASPSource codeTo intercept HTTP requests (for example, process the intercepted Request Parameters and then send them to other subsystems. At the same time, it does not affect the normal operation of the original ASP project), there are two ways:

A)Develop the ISAPI filter by yourself, and add the DLL you have developed to the ISAPI filter in IIS.

This method is cumbersome, technical difficulty is relatively high, in today's. Net Era, do not recommend everyone to use, interested can refer to an open source project: http://filterdotnet.codeplex.com/

And ISAPI DevelopmentArticleFor example

ISAPI development Introduction http://blog.csdn.net/mycoolx/article/details/6913048

ISAPI tutorial for Delphi developers http://delphi.about.com/library/bluc/text/uc060901c.htm

Delphi iis isapi http://www.cnblogs.com/cisky/archive/2011/01/05/1926249.html

Delphi iis isapi http://siyebocai.blog.163.com/blog/static/103316426200810297512408/

Use Delphi to compile IIS ISAPIProgramHttp://download.csdn.net/detail/wwwvvingnet/2229146

Debug ISAPI program http://bbs.csdn.net/topics/7979 with IIS or PWS in Delphi

B)Use Asp.net's httpmodule (Environment: iis7/ASP. NET 4.0 passed the test)

Prerequisites:The application pool used by the ASP project must use"Integration"Mode

Create an httpmodule first

Using system; using system. io; using system. web; namespace asp_aspx_test {public class myhttpmodule: ihttpmodule {string logfilename; Public myhttpmodule () {logfilename = httpcontext. current. server. mappath ("~ /Log/request. log ");} public void dispose () {} public void Init (httpapplication context) {context. beginrequest + = beginrequesthandle; context. endrequest + = endrequesthandle;} private void beginrequesthandle (Object source, eventargs e) {httpapplication application = (httpapplication) source; httpcontext context = application. context; httprequest request = context. request; file. appendalltext (logfilename, environment. newline + request. URL + environment. newline + "beginrequest =>" + datetime. now. tostring ("yyyy-mm-dd hh: mm: SS") + environment. newline); foreach (VAR item in request. querystring. allkeys) {file. appendalltext (logfilename, String. format ("querystring => {0 }:{ 1}", item, request. querystring [item]) + environment. newline);} foreach (VAR item in request. form. allkeys) {file. appendalltext (logfilename, String. format ("form => {0 }:{ 1}", item, request. form [item]) + environment. newline);} context. response. write ("beginrequesthandle <br/>");} private void endrequesthandle (Object source, eventargs e) {httpapplication application = (httpapplication) source; httpcontext context = application. context; httprequest request = context. request; file. appendalltext (logfilename, environment. newline + request. URL + environment. newline + "endrequest =>" + datetime. now. tostring ("yyyy-mm-dd hh: mm: SS") + environment. newline); foreach (VAR item in request. querystring. allkeys) {file. appendalltext (logfilename, String. format ("querystring => {0 }:{ 1}", item, request. querystring [item]) + environment. newline);} foreach (VAR item in request. form. allkeys) {file. appendalltext (logfilename, String. format ("form => {0 }:{ 1}", item, request. form [item]) + environment. newline);} context. response. write ("endrequesthandle <br/> ");}}}

Here is just the Demo code. I recorded all the querystring and form parameters in the request.

Modify configuration in Web. config

 
<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <system. web> <compilation DEBUG = "true" targetframework = "4.0"/> </system. web> <system. webserver> <modules runallmanagedmodulesforallrequests = "true"> <Add name = "myhttpmodule" type = "asp_aspx_test.myhttpmodule, asp_aspx_test"/> </modules> </system. webserver> </configuration>

Note:Iis7 and later versions, custom httpmodule, must be addedSystem. WebserverNode. Otherwise, only Asp.net requests can be blocked and ASP requests are invalid.

Finally, I will give you a tips on ASP debugging. (Since Asp.net came out, many people probably haven't touched ASP for a long time, just like me. These tips are almost lost, so I will post them here to back up)

Remove it from IE browser firstFriendly ErrorCheck

In IIS settings,Allow sending detailed errors to the client

In this way, the detailed information is displayed when an ASP code error occurs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.