小编Ser*_*e P的帖子

HttpContext.Current在异步Callback中为null

试图访问HttpContext.Current一个方法调用回来,我可以修改一个Session变量,但我收到的异常HttpContext.Currentnull.当_anAgent对象触发它时,异步触发回调方法.

在查看SO上的类似 问题之后,我仍然不确定解决方案.

我的代码的简化版本如下所示:

public partial class Index : System.Web.UI.Page

  protected void Page_Load()
  {
    // aCallback is an Action<string>, triggered when a callback is received
    _anAgent = new WorkAgent(...,
                             aCallback: Callback);
    ...
    HttpContext.Current.Session["str_var"] = _someStrVariable;
  }

  protected void SendData() // Called on button click
  {
    ...
    var some_str_variable = HttpContext.Current.Session["str_var"];

    // The agent sends a message to another server and waits for a call back
    // which triggers …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net wcf asynchronous

21
推荐指数
3
解决办法
3万
查看次数

Owin auth - 如何获取请求身份验证令牌的客户端的IP地址

使用Owin Security,我试图让API有2种身份验证方法.

context变量(OAuthGrantResourceOwnerCredentialsContext)中是否有一个属性可以让我访问客户端IP地址,向API发送auth令牌的初始请求?

我的auth方法的基本条带如下所示:

public override async Task GrantResourceOwnerCredentials(
    OAuthGrantResourceOwnerCredentialsContext context)
{
    await Task.Run(() =>
    {
        var remoteIpAddresss = context.Request.RemoteIpAddress;
        var localIpAddress = context.Request.LocalIpAddress;


        // ... authenticate process goes here (AddClaim, etc.)
    }
}
Run Code Online (Sandbox Code Playgroud)

根据我的理解remoteIpAddresslocalIpAddressAPI(即API的托管位置).我如何知道请求从哪个IP地址(和端口)发送?

客户是否需要自己发送此信息?

我应该在auth路径中添加额外的参数吗?(除了典型username,password,grant_type)?

.net c# authentication owin

13
推荐指数
1
解决办法
8599
查看次数

从DbContext检索DbSet <T>的通用方法

我正在使用Entity Framework和一个大型数据库(由200多个表组成).

尝试创建一个返回DbSet<T>特定表T(即类,可以是TableA)的泛型方法.

使用实体数据模型(自动)创建的实体类如下所示:

public partial class sqlEntities : DbContext
{

    public virtual DbSet<TableA> TableA { get; set; }
    public virtual DbSet<TableB> TableB { get; set; }
    public virtual DbSet<TableC> TableC { get; set; }
    ... // other methods

}
Run Code Online (Sandbox Code Playgroud)

我的主要课程是这样的

public class TableModifier
{
   // Should return first 10 elements from a table of that type T
   public IQueryable<T> GetFromDatabase<T>() where T : EntityObject
   {
       try
       {
           using (sqlEntities ctx = new sqlEntities()) …
Run Code Online (Sandbox Code Playgroud)

c# generics entity-framework

12
推荐指数
2
解决办法
2万
查看次数

Jquery UI自动完成:从一个数组的多个属性中搜索

嗨,我正在尝试让jQuery UI自动完成小部件工作,以便它搜索来自我的数组的多个属性的匹配(不仅仅是默认情况下它的一个).

我已经搞乱了他们的例子,但是我仍然不确定如何解决这个问题.

http://jsfiddle.net/FUZPN/

这是我的数组格式 script

var projects = [
    {
        value: "jquery",
        label: "jQuery",
        desc: "the write less, do more, JavaScript library",
        other: "9834275 9847598023 753425828975340 82974598823"
    },
    {
        value: "jquery-ui",
        label: "jQuery UI",
        desc: "the official user interface library for jQuery",
        other: "98 83475 9358 949078 8 40287089754 345 2345"
    },
    {
        value: "sizzlejs",
        label: "Sizzle JS",
        desc: "a pure-JavaScript CSS selector engine",
        other: "49857 2389442 573489057 89024375 928037890"
    }
Run Code Online (Sandbox Code Playgroud)

我正在寻找的是,如果你输入"write",第一个元素应该在自动完成中弹出,同样如果你输入"jq",前两个元素应该弹出.


根据文件:

数组:数组可用于本地数据.有两种支持的格式:

  • 字符串数组: …

jquery jquery-ui jquery-ui-autocomplete

10
推荐指数
1
解决办法
8544
查看次数

div在没有被拖动的情况下移动时未更新jsPlumb端点

我正在使用jsPlumb.我有.project容纳.taskdiv的容器.这些.taskdiv是jsPlumb连接的源/目标.该.project容器是可拖动.

http://jsfiddle.net/8Af7s/

在创建.taskdiv(使用jQuery创建)时,会为div分配源/目标属性:

 // Makes the task div a possible target (i.e. connection can be dragged to)
 jsPlumb.makeTarget(newState, {
   anchor:["Continuous", { faces:["left", "right"] } ]
 });

 // Makes the task div a possible source (i.e. connection can be dragged from)
 jsPlumb.makeSource(newState, {
   anchor:["Continuous", { faces:["left", "right"] } ]
 });
Run Code Online (Sandbox Code Playgroud)

.tasknewState

 var newState = $('<div>').attr('id', id).addClass('task')
Run Code Online (Sandbox Code Playgroud)

现在要删除一个任务,我有一个静态按钮,它只是分离与该任务的所有连接并将其删除:

 $('#removetask1').click(function(e) {
     jsPlumb.detachAllConnections($('#task1'));
     $('#task1').remove();
     //jsPlumb.repaintEverything();
 })
Run Code Online (Sandbox Code Playgroud)

task …

javascript jquery jsplumb

5
推荐指数
1
解决办法
1743
查看次数

如何读取HttpRequest的主体发布到REST Web服务 - C#WCF

我有一个Apex类(SalesForce中的一个类),可以调用REST Web服务.

public class WebServiceCallout 
{
    @future (callout=true)
    public static void sendNotification(String aStr) 
    {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://xx.xxx.xxx.xx:41000/TestService/web/test');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setBody(aStr); // I want to read this in the web service

        try 
        {
            res = http.send(req);
        } 
        catch(System.CalloutException e) 
        {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

REST Web服务(C#,WCF)如下所示:

public interface ITestService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
     ResponseFormat = WebMessageFormat.Json,
     BodyStyle = WebMessageBodyStyle.Bare,
     UriTemplate …
Run Code Online (Sandbox Code Playgroud)

c# rest wcf web-services salesforce

4
推荐指数
1
解决办法
8983
查看次数

由于EndpointDispatcher上的AddressFilter不匹配,无法在接收方处理带有To'...'的消息

我正在尝试实现WCF Rest服务而不修改App.config文件.

我的服务界面如下所示:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "/teststr/?string={aStr}")]
    string TestString(string aStr);
}
Run Code Online (Sandbox Code Playgroud)

服务实现非常基础:

public class TestService : IService
{
    public string TestString(string aStr = null)
    {
        Console.WriteLine("The Test() method was called at {0}"
            + "\n\rThe given string was {1}\n\r"
            , DateTime.Now.ToString("H:mm:ss")
            , aStr);

        return aStr;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的主要程序运行一切:

// Step 1 Create a URI to serve as the base address.
Uri baseAddress …
Run Code Online (Sandbox Code Playgroud)

c# rest wcf

4
推荐指数
1
解决办法
8570
查看次数

jsPlumb 如何删除重复的连接

我试图避免在使用jsPlumb 时有重复的连接(2 个连接具有相同的源和目标)。有没有办法在不必修改 jsPlumb.js 本身的情况下做到这一点?

http://jsfiddle.net/uQdfq/
(从拖动task1task3 两次

我不想像 ( 1 )那样有添加特定端点的限制。

我的.tasks 在被调用时被定义为可能的目标/源 - 即整个 div 可以是源/目标,而不仅仅是某个端点:

  addTask($('#project1'), 'task' + 1);
Run Code Online (Sandbox Code Playgroud)

函数本身:

// Adds a task div to the specific project
function addTask(parentId, id) {
  var newState = $('<div>').attr('id', id).addClass('task')

  // A title for the task
  var title = $('<div>').addClass('title').text(id);
  newState.append(title);

  $(parentId).append(newState);

  // Makes the task div a possible target (i.e. connection can be dragged to)
  jsPlumb.makeTarget(newState, {
    anchor: 'Continuous'
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery jsplumb

3
推荐指数
1
解决办法
1577
查看次数