惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
Engineering at Meta
Engineering at Meta
S
Securelist
M
MIT News - Artificial intelligence
GbyAI
GbyAI
O
OpenAI News
W
WeLiveSecurity
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
博客园_首页
C
Check Point Blog
Martin Fowler
Martin Fowler
The Last Watchdog
The Last Watchdog
量子位
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
雷峰网
雷峰网
H
Heimdal Security Blog
P
Palo Alto Networks Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 聂微东
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
Help Net Security
Help Net Security
U
Unit 42
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
Jina AI
Jina AI
美团技术团队
L
LINUX DO - 热门话题
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
P
Privacy International News Feed
博客园 - 司徒正美

博客园 - BigRain

小学生学习汉字,汉字抓取 c# regex regextools cache 访问频率的思考 python 百度cpc点击 20130118SQL记录 PPT辅助工具 检查外链的方法 百度调价HttpWebRequest 装饰者模式 第一个android程序闪亮登场 SQL 的一些批量插入和修改 职责链模式的运用 State Pattern 程序人生 SerialPort实现modem的来电显示 利用枚举进行状态的设计 singleton模式 在软件开发中的运用 我对当前项目的一些看法 闲话闲说——关于异常
webService启用cookie的另一种方法
BigRain · 2012-06-14 · via 博客园 - BigRain

很多时候,我们希望用到asp.net的membership,这样就可以快速的处理角色验证之类的问题。而且客服端能够与bs系统共用一套账户。

webservice里面的proxy类继承自WebClientProtocol,而在WebClientProtocol里面包含两个方法

protected virtual WebRequest GetWebRequest(Uri uri);

protected virtual WebResponse GetWebResponse(WebRequest request);

我们应该很清楚,调用webservice本质上也是一个http的Post请求,和普通的html不一样的是,webservice请求的内容和服务返回的内容不是html,而是xml(soap协议)。再看这两个方法,所以proxy在调用service的时候,肯定会调用到这两个方法。所以,我们只要进行适当的重写这两个方法就OK了。

private static string currentCookie = string.Empty;
        protected override WebRequest GetWebRequest(Uri 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;
        }

我们直接从http请求的header里面去截取cookie,在放送之前,在Request的header上附加上cookie。

服务端,web.config需要配置一下,

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

启用所有module通道,这样就会进行权限验证。