REST WCF服务和会话的ASP.NET [英] REST WCF service and Session‏ in ASP.NET

查看:134
本文介绍了REST WCF服务和会话的ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以请你帮忙。

我一直在试图从一个WCF REST服务访问一个asp.net应用程序的当前会话对象。

I have been trying to access the current session object of an asp.net application from within a WCF REST service.

目前还没有成功可言。从服务访问会话对象是不一样的一个在aspx页面。

There has been no success at all. the session object accessed from the service is not the same one in the aspx pages.

所以,这里是我的问题:是否有可能访问当前会话中的 REST WCF服务,通过HttpContext.Current.Session

So, here is my question: Is it possible to access the current session in a REST WCF service through HttpContext.Current.Session ?

在code有以下几点:

The code has the following points:

 [AspNetCompatibilityRequirements
(RequirementsMode = 
AspNetCompatibilityRequirementsMode.Allowed)] // I have also tried Required
public class DataService : IDataService

在web.config中:

in web.config:

<system.serviceModel>
  <behaviors>
   <endpointBehaviors>
    <behavior name="ClosedRoom.DataServiceBehavior">
     <enableWebScript />
    </behavior>
   </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
  <baseAddressPrefixFilters>
        <add prefix="http://localhost:63399"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

  <services>
    <service name="ClosedRoom.DataService">
      <endpoint address="" behaviorConfiguration="ClosedRoom.DataServiceBehavior"
        binding="webHttpBinding" contract="ClosedRoom.IDataService" />
    </service>
  </services>
</system.serviceModel>

感谢您,

推荐答案

为了一个会议上rehidrated,您需要提供一个密钥。在一个正常的asp.net应用程序的关键是通过用户或者通过cookie,或URL参数提供的。

In order for a session to be rehidrated, you need to supply a key. In a normal asp.net application that key is supplied by user either via cookie or url parameter.

你是如何计划收购来自REST客户端密钥?如何认证后的客户拿到钥匙开始?当它们存储的关键?

How are you planning to acquire that key from the REST client? How those clients get that key initially after the authentication? Where they store the key?

这就是为什么大多数的基于REST的服务需要API访问密钥,另一种密钥签署每个请求。

This is why most of the REST based services take a api access key and also another key to sign every request.

恕我直言,会议无关的基于REST的设计。

IMHO sessions are irrelevant in REST based designs.

这篇关于REST WCF服务和会话的ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆