从上下文

时间:2015-11-26 14:29:06

标签: c# asp.net-mvc signalr

我可以在 SignalR hub 中获取当前的操作/控制器名称,就像使用HttpContext的常用MVC控制器一样吗?

目前我正在使用:

if (HttpContext.Current != null)
    return HttpContext.Current.Request.RawUrl;

但这只会返回如下内容:

http://localhost:5226/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=...&connectionData=...name...xhub...name...yhub...&tid=1

HubCallerContext似乎没有更多信息。

有人有想法吗?

2 个答案:

答案 0 :(得分:1)

我发现我可以使用SignalR's Hub pipeline

package org.tooj;


import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;


import org.qtproject.qt5.android.bindings.QtActivity;

public class ToojActivity extends QtActivity{



private static ToojActivity instance;
private boolean _transparentStatusBar = false;
private boolean _transparentNavigationBar = false;

public ToojActivity(){
    instance = this;
    Log.i("ToojActivity", "ctor");





}

   @TargetApi(Build.VERSION_CODES.KITKAT)
   @Override
   public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    Intent svc=new Intent(this, Player.class); // call service
    startService(svc);




public static ToojActivity getInstance() {
    return ToojActivity.instance;
}

public void SetStatusBarIsTransparent(boolean value) {
    _transparentStatusBar = value;
}

public void GetNavigationBarIsTransparent(boolean value) {
    _transparentNavigationBar = value;
}

public boolean GetStatusBarIsTransparent() {
    return _transparentStatusBar;
}

public boolean GetNavigationBarIsTransparent() {
    return _transparentNavigationBar;
}

}

这样我可以将Action / Controller设置为全局对象并稍后访问。这当然不是最佳的。

答案 1 :(得分:0)

您可以尝试从RouteData对象

中获取值
       var controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
       var action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();

希望这有帮助