sessionState.cookieName 设置在 WCF REST 中不起作用

发布于 2024-12-05 11:13:42 字数 902 浏览 0 评论 0原文

我想在 WCF REST 服务中将 cookie 名称设置为不同的名称。

我已经在 Web.config 上设置了它:

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <sessionState timeout="99999" mode="InProc" cookieName="xxx"/>
  </system.web>

但它不起作用:

请求:

POST http://localhost/wcfrest/logon HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
Content-Length: 40

{"Username":"sdf","Password":"sadfsdaf"}

响应:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 19
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Set-Cookie: .ASPXAUTH=780210B[...]7627C58; expires=Thu, 22-Sep-2011 11:46:06 GMT; path=/
X-Powered-By: ASP.NET
Date: Wed, 21 Sep 2011 11:46:06 GMT

{"Successful":true}

我还应该做任何其他更改吗?

谢谢。

I want to set the cookie name to a different one in my WCF REST service.

I have set it on the Web.config:

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <sessionState timeout="99999" mode="InProc" cookieName="xxx"/>
  </system.web>

But it does not work:

Request:

POST http://localhost/wcfrest/logon HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
Content-Length: 40

{"Username":"sdf","Password":"sadfsdaf"}

Response:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 19
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Set-Cookie: .ASPXAUTH=780210B[...]7627C58; expires=Thu, 22-Sep-2011 11:46:06 GMT; path=/
X-Powered-By: ASP.NET
Date: Wed, 21 Sep 2011 11:46:06 GMT

{"Successful":true}

Is there any other change I should do?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-12-12 11:13:42

因此,您的请求/响应不会显示会话 cookie。响应具有名为 .ASPXAUTH 的身份验证 cookie(请注意,会话和身份验证在 ASP.NET 中具有不同的范围并使用不同的 cookie)。如果您使用表单身份验证,则可以使用 身份验证配置元素

为了生成会话 cookie,您必须在会话中写入一些值。生成会话 cookie 后,您可以看到它在每个请求中遍历。顺便说一句,您必须启用ASP.NET 兼容性模式才能参与 ASP WCF 服务中的 .NET 管道(包括会话状态)。

As such your request/response does not show session cookie. Response has authentication cookie named .ASPXAUTH (note that session and authentication has different scope in ASP.NET and uses different cookies). If you are using forms authentication then you can change this cookie name using name attribute in authentication configuration element.

For session cookie to get generated, you must write some value into your session. Once session cookie gets generated, you can see it traversing in each request. BTW, you have to enable ASP.NET compatibility mode for participating in ASP.NET pipeline (including session state) in WCF services.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文