小编Sex*_*yMF的帖子

HttpContext.Current.Request.UserHostAddress为null

  1. 在我的Dev Machine中HttpContext.Current.Request.UserHostAddress为null.为什么?我怎么能打开它?
  2. 如果是代理客户端,如何获取Ips列表?

使用ASP.net 4 window7的WCF服务.

谢谢

c# ip-address

11
推荐指数
1
解决办法
6286
查看次数

ASP.NET MVC - Session为null

我在.net4上有一个MVC3应用程序,它的会话在dev环境中工作,但不在生产环境中.
在制作中我记录了sessionID,它在我设置和从会话中获取的时刻是相同的.

当我试图获得会话时,我得到了Null Exception.

这是我访问会话的方式:

public static class HandlersHttpStorage
{
    public static string TestSession
    {
        get
        {
            return HttpContext.Current.Session["time"];//This is null
        }
        set
        {
            HttpContext.Current.Session.Add("time", value);//DateTime.Now.ToString()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

令我担心的是,即使web.config是相同的,生产中的行为也不同于开发.

asp.net session asp.net-mvc-3

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

了解MongoDB新C#驱动程序中的更改(异步和等待)

新的C#驱动程序完全是Async,在我的理解中,在n层架构中扭曲了一些旧设计模式,例如DAL.

在我的Mongo DALs中我用来做:

public T Insert(T entity){
     _collection.Insert(entity);
     return entity;
}
Run Code Online (Sandbox Code Playgroud)

这样我就能得到坚持ObjectId.

今天,一切都是Async等InsertOneAsync.
如何将Insert方法现在将返回entityInsertOneAsync会做些什么呢?你能举个例子吗?

c# mongodb mongodb-csharp-2.0 mongodb-.net-driver

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

无法捕捉laravel中的异常

我有以下情况:

  try {

        DB::beginTransaction();

        $task = new Task();
        $task->setTracker("");
        //thrown \Symfony\Component\Debug\Exception\FatalThrowableError


            DB::commit();

        }catch (\Exception $e){
            DB::rollBack();
            Log::error($e);
            //throw $e;
        }
Run Code Online (Sandbox Code Playgroud)

我没有进入捕捞区.
知道为什么吗?

更新

这是抛出的错误:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 1 passed to App\Models\Task::setTracker() must be an instance of Carbon\Carbon, integer given, called in /var/www/app/Services/ShareLogic.php on line 60

并且不会被抓住

谢谢

php try-catch laravel php-7.1 laravel-5.4

10
推荐指数
2
解决办法
6778
查看次数

elasticsearch = 无法分配,因为不允许分配给任何节点

我将 Elasticsearch 作为单节点集群。
其中一项索引为黄色,解释如下。
我已经阅读了这里的所有材料,总的来说,我没有找到这个问题的解决方案。这是索引信息:
yellow open research-pdl 8_TrwZieRM6oBes8sGBUWg 1 1 416656058 0 77.9gb 77.9gb

这个命令POST _cluster/reroute?retry_failed似乎没有做任何事情。

安装程序在 docker 上运行,我有 650GB 可用空间。

{
  "index" : "research-pdl",
  "shard" : 0,
  "primary" : false,
  "current_state" : "unassigned",
  "unassigned_info" : {
    "reason" : "CLUSTER_RECOVERED",
    "at" : "2020-12-16T05:21:19.977Z",
    "last_allocation_status" : "no_attempt"
  },
  "can_allocate" : "no",
  "allocate_explanation" : "cannot allocate because allocation is not permitted to any of the nodes",
  "node_allocation_decisions" : [
    {
      "node_id" : "5zzXP2kCQ9eDI0U6WY4j9Q",
      "node_name" : "37f65704d9bb",
      "transport_address" : "172.19.0.2:9300", …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

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

如何在C#MVC 3中返回空白视图

我想为某个控制器返回一个空白页面.

空白,我的意思是空白!没有Site.Master内容.

怎么样?谢谢

c# asp.net-mvc

9
推荐指数
1
解决办法
7476
查看次数

如何验证密码是否包含X大写字母和Y数字?

如何在C#中验证密码至少包含X个大写字母和至少Y个数字,并且整个字符串长于Z?

谢谢.

c# string-matching

8
推荐指数
2
解决办法
5352
查看次数

Javascript - 生成随机深色

我有这种方法为我生成随机颜色的字体:

function getRandomRolor() {
     var letters = '0123456789ABCDEF'.split('');
     var color = '#';
     for (var i = 0; i < 6; i++) {
         color += letters[Math.round(Math.random() * 15)];
     }
     return color;
}  
Run Code Online (Sandbox Code Playgroud)

问题是字体总是在白色背景上,我想生成深色.
可能吗?
谢谢

javascript random colors

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

PHP投射到我的班级

为什么这是不可能的:

$user = (User) $u[0];
Run Code Online (Sandbox Code Playgroud)

但这是可能的

$bool = (boolean) $res['success'];
Run Code Online (Sandbox Code Playgroud)

我使用PHP 7.0.

php casting

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

使用带有静态页面插件的前端编辑器

我真的很新ocms,我已经安装了静态页面,它的工作非常好.我想使用其中一个插件编辑首页(在上下文编辑中)的字段,例如:https://octobercms.com/plugin/netsti-editor我已经拖到我的布局页面,但我可以' t在首页编辑此内容.这是我如何使用静态页面插件的示例:

<img src="{mediafinder name="logo" label="Logo" tab="General" mode="image"}{/mediafinder}" />

{repeater name="side_logos" tab="General" prompt="Add another content section"} {text name="my_title" label="My Title"}{/text} {/repeater}
Run Code Online (Sandbox Code Playgroud)

谢谢

php octobercms octobercms-plugins

8
推荐指数
1
解决办法
442
查看次数