Another way for WebService to enable cookie

Source: Internet
Author: User

Most of the time, we want to use Asp.net's membership to quickly handle problems such as role verification. In addition, the customer service can share a set of accounts with the BS system.

The proxy class in WebService inherits from webclientprotocol, And the webclientprotocol contains two methods.

Protected virtual webrequest getwebrequest (URI );

Protected virtual webresponse getwebresponse (webrequest request );

It should be clear that calling WebService is essentially an http post request. Unlike ordinary HTML, the content of the WebService request and the content returned by the service are not HTML, but XML (SOAP protocol ). Let's look at these two methods again, so the proxy will certainly call these two methods when calling the service. Therefore, we only need to rewrite the two methods as appropriate.

Private Static string currentcookie = string. Empty; protected override webrequest getwebrequest (URI) {webrequest request = base. getwebrequest (URI); If (! String. isnullorempty (currentcookie) {request. headers [httprequestheader. cookie] = currentcookie;} return request;} protected override webresponse getwebresponse (webrequest request) {webresponse response = base. getwebresponse (request); If (! String. isnullorempty (response. headers [httpresponseheader. setcookie]) currentcookie = response. headers [httpresponseheader. setcookie]; return response ;}

We directly intercept the cookie from the HTTP request header. before sending the cookie, We append the cookie to the request header.

Server, Web. config needs to be configured,

<System. webserver> <modules runallmanagedmodulesforallrequests ="True"/> </System. webserver>

Enable all module channels to verify permissions.

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.