小编Jun*_*ior的帖子

“socket.io.js”文件在哪里?

我正在尝试设置一个 WebSocket 来运行一个简单的聊天应用程序。

我有一个用户使用在服务器 A 上运行的 PHP 应用程序。另一方面,我有服务器 B,它使用 node.js 和 Socket.io 运行 WebSocket。

我按照Socket.io教程编写了一个小型聊天应用程序。但似乎我需要socket.io.js在我的客户端脚本中包含该文件以启动用户和 Websocket 之间的连接。但是,我似乎无法弄清楚从哪里获取socket.io.js文件。

socket.io.js在哪里可以找到?

不确定我的代码在这种情况下是否重要,但如果需要,这里是。

这是我的 socket.js 文件“Websocket”服务器

var env = require('./config');

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(env.socket.port, env.socket.host, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

app.get('/', function (req, res) {
    res.send('Landed!');
});

io.on('connection', function (socket) {
  socket.emit('news', { …
Run Code Online (Sandbox Code Playgroud)

javascript sockets websocket node.js socket.io

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

如何解密用Rijndael-256加密的node.js中的消息?

我有一条消息,使用PHP加密,然后存储在MySQL数据库中.

我需要能够使用node.js/javascript解密此消息.

在研究如何做到这一点时,我遇到了加密模块.我试图使用它,但我遇到了以下错误

C:\Program Files\nodejs\node_modules\mysql\lib\protocol\Parser.js:82
        throw err;
              ^
TypeError: Not a buffer
    at TypeError (native)
    at new Decipheriv (crypto.js:282:16)
    at Object.Decipheriv (crypto.js:279:12)
    at Query.<anonymous> (C:\Program Files\nodejs\modules\validator.js:76:27)
    at Query._callback (C:\Program Files\nodejs\modules\dbconnect.js:46:14)
    at Query.Sequence.end (C:\Program Files\nodejs\node_modules\mysql\lib\protoc
ol\sequences\Sequence.js:96:24)
    at Query._handleFinalResultPacket (C:\Program Files\nodejs\node_modules\mysq
l\lib\protocol\sequences\Query.js:144:8)
    at Query.EofPacket (C:\Program Files\nodejs\node_modules\mysql\lib\protocol\
sequences\Query.js:128:8)
    at Protocol._parsePacket (C:\Program Files\nodejs\node_modules\mysql\lib\pro
tocol\Protocol.js:274:23)
    at Parser.write (C:\Program Files\nodejs\node_modules\mysql\lib\protocol\Par
ser.js:77:12)
Run Code Online (Sandbox Code Playgroud)

这就是我尝试使用加密模块来描述消息的方法

var crypto = require('crypto');
var encryptedText = new Buffer(rows[0]['password'], 'base64');
var decipher = crypto.createDecipheriv('sha256', 'The encryption password', 32);
var decrypted = decipher.update(encryptedText, …
Run Code Online (Sandbox Code Playgroud)

javascript php encryption rijndael node.js

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

如何在身份2中将Id属性从字符串转换为int

我正在使用ASP.NET MVC 5 / Entity 6 frameworke和代码优先方法在c#中构建应用程序。我正在尝试将Id身份2中的属性从更改stringinteger

我遵循的文档似乎很简单。

然后,我使用以下命令创建迁移

Add-Migration InitialCreate
Run Code Online (Sandbox Code Playgroud)

由于某种原因,迁移文件中不包含AspNet表。但是,然后我使用以下命令进行了迁移

Update-Database
Run Code Online (Sandbox Code Playgroud)

迁移没有问题,播种机运行良好。

但是,当我运行应用程序时

我收到以下错误

异常详细信息:System.FormatException:输入字符串的格式不正确。

该错误突出显示了Startup.Auth.cs文件下面的第38行。

Line 36: regenerateIdentityCallback: (manager, user) =>
Line 37: user.GenerateUserIdentityAsync(manager),
Line 38: getUserIdCallback: (id) => (id.GetUserId<int>()))
Run Code Online (Sandbox Code Playgroud)

如何解决此错误?

c# asp.net-mvc asp.net-identity

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

'#333333'不是有关XAML的Setter上'System.Windows.Controls.Border.BorderBrush'属性的有效值

我正在尝试使用WPF创建一个小应用程序.我想在文本框中添加带圆角的边框.同时,我将全局值添加到App.xaml文件中,以便我可以重用这些颜色.

这是我在App.xaml文件中添加的内容

<Application.Resources>
    <System:String x:Key="TextRegular">#333333</System:String>
    <System:String x:Key="TextDanger">#dc3545</System:String>
    <System:String x:Key="TextInput">#495057</System:String>
    <System:String x:Key="InputBorder">#80bdff</System:String>


    <Style x:Key="FormControl" TargetType="TextBox">
        <Setter Property="Padding" Value="5" />
        <Setter Property="FontSize" Value="14" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="BorderThickness" Value="1" />
    </Style>

    <Style x:Key="FormInputBorder" TargetType="Border">
        <Setter Property="BorderBrush" Value="{StaticResource TextRegular}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="3" />
    </Style>

    <Style x:Key="FormLabel" TargetType="Label">
        <Setter Property="Padding" Value="5" />
        <Setter Property="FontSize" Value="14" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <!-- <Setter Property="Foreground" Value="{StaticResource TextRegular}" /> -->
    </Style>

    <Style x:Key="HasError" TargetType="TextBlock">
        <Setter Property="Padding" Value="5" />
        <Setter Property="VerticalAlignment" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

如何使用c#检查类是否实现并与泛型接口?

我有以下界面

public interface IHandleSuccess<T> where T : Event
{
    void Finished(T _event, Listener<T> listener);
}
Run Code Online (Sandbox Code Playgroud)

以下课程

public abstract class Listener<T> where T : Event
{
    public abstract void Handle(T _event);
}
Run Code Online (Sandbox Code Playgroud)

以下类扩展Listener<T>和实现IHandleSuccess<T>

public class SendConfirmationEmail : Listener<UserWasUpdated>, IHandleSuccess<UserWasUpdated>
{
    public override void Handle(UserWasUpdated _event)
    {
        // ...
    }

    public void Finished(UserWasUpdated _event, Listener<UserWasUpdated> listener)
    {
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,另一个扩展Listener<T>但未实现的侦听器IHandleSuccess<T>

public class ScheduleOriantation: Listener<UserWasUpdated>
{
    public override void Handle(UserWasUpdated _event)
    {
        // ...
    } …
Run Code Online (Sandbox Code Playgroud)

c#

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

请求的身份验证凭据无效。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据

C#我有一个在 .NET Core 2.2 框架之上编写的控制台应用程序。

我正在尝试使用我的应用程序连接 Google 我的商家 API 来创建帖子

但每次我尝试调用 REST API 时都会收到以下错误

请求的身份验证凭据无效。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。请参阅 https://developers.google.com/identity/sign-in/web/devconsole-project

该代码以前可以工作,但由于某种奇怪的原因,它停止了!

这是一个示例,我获取身份验证令牌,然后调用 API 来获取Google 帐户列表。

var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
    ClientId = "Client ID",
    ClientSecret = "Client Secret",
}, new[] { "https://www.googleapis.com/auth/plus.business.manage" }, "google username", CancellationToken.None);

using (var client = new HttpClient())
{   
    //client.DefaultRequestHeaders.Clear();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", credential.Token.AccessToken);
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    var c = await client.GetAsync("https://mybusiness.googleapis.com/v4/accounts");
    var accountContentss = await c.Content.ReadAsStringAsync();
    c.EnsureSuccessStatusCode(); …
Run Code Online (Sandbox Code Playgroud)

c# google-api google-oauth google-api-dotnet-client google-my-business-api

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

添加 - 迁移一个列名称会多次列出

我创建了所有模型,然后添加了一个新的迁移Add-Migration Initial.

添加迁移会在迁移文件夹中创建一个预期的迁移文件,但由于某种原因,它创建了一个名为client_idtwo 的列.我期望创建一个名为client_id整数类型但不可为空的列.

我应该注意,该列client_id引用了Clients具有关系的模型.

这是我的模型类的样子

[Table("scripter_campaigns")]
public class Campaign
{
    [Key]
    [Column(Order = 1)]
    public int id { get; set; }

    [Column(Order = 2)] 
    [StringLength(200)]
    [Required]
    [MinLength(5, ErrorMessage = "The title must be greater than 5 characters  in length"), 
     MaxLength(200)] 
    public string name { get; set; }

     [Column(Order = 3)] 
    [StringLength(200)]
    public string layout { get; set; }

     [Column(Order = 4)] 
    [StringLength(200)] 
    public string call_list_server_name { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework

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

如何使用JavaScript更新或添加数组中的值?

我在JavaScript中使用变量中的数组数组.我想用子数组更新一个值,而不必临时复制数组.

这是一个例子.

我有这个数组

var data= [{
             '123':  [{'a': 10, 'b': 20, 'c': 30, 'd': 40}],
             '456':  [{'a': 1, 'b': 2, 'c': 3, 'd': 4}]
          }];
Run Code Online (Sandbox Code Playgroud)

我希望能够更改a123键内部的值(如果a存在).否则,我想创建该密钥.此外,如果子数组中不存在'a',我想添加它而不是抛出错误.

我想更新

data['123']['assigned_at'] = 'value';
Run Code Online (Sandbox Code Playgroud)

但由于assigned_at不存在,我收到此错误

无法设置未定义或空引用的属性"assigned_at".

如何正确更新阵列?

javascript arrays jquery

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

如何在Laravel中使用form-request时检查验证是否失败?

我正在尝试为API编写CRUD.但是,当验证失败时,我想要返回json基于错误的响应,而不是将用户重定向到主页.

我可以使用以下代码执行此操作

public function store(Request $request)
{
    try {
        $validator = $this->getValidator($request);

        if ($validator->fails()) {
            return $this->errorResponse($validator->errors()->all());
        }

        $asset = Asset::create($request->all());

        return $this->successResponse(
            'Asset was successfully added!',
            $this->transform($asset)
        );
    } catch (Exception $exception) {
        return $this->errorResponse('Unexpected error occurred while trying to process your request!');
    }
}

/**
 * Gets a new validator instance with the defined rules.
 *
 * @param Illuminate\Http\Request $request
 *
 * @return Illuminate\Support\Facades\Validator
 */
protected function getValidator(Request $request)
{
    $rules = [
        'name' => 'required|string|min:1|max:255', …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 laravel-5.4 laravel-5.5

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

是否可以在运行时使用两个不同的 Owin 启动文件?

我正在使用带有MEF 框架的 Asp.net MVC 5 应用程序,以允许我将 MVC 应用程序设计为主应用程序中的插件。

我需要我的一个插件需要有自己的OwinStartup 类,该类在属于我的主应用程序的主 Owin 类之后运行。

换句话说,main.dllStartup一个总是需要先运行plugin.dllStartup类,然后有一个需要第二个运行的类。

是否可以拥有 2 个自己的创业班?

来自关于检测StartUp 类的文档

OwinStartup属性会覆盖命名约定。您还可以使用此属性指定友好名称,但是,使用友好名称需要您还使用appSetting配置文件中的元素。

所以我试着像这样添加一个友好的名字

[assembly: OwinStartup("pluginStartup", typeof(plugin.Startup))]
Run Code Online (Sandbox Code Playgroud)

在配置文件中添加了以下内容

<appSettings>  
  <add key="owin:appStartup" value="Main.Startup, Main" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

但这并没有归档我Plugin.Startup它只运行Main.Startup.

有没有办法运行两个不同的Startup类?

https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection

c# asp.net-mvc mef owin asp.net-mvc-5

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

错误代码:1044。拒绝用户访问

在使用MySQL登录时 'root'@10.0.1.15'

我试图授予用户,SELECT, INSERT, UPDATE但从MySQL得到此错误

Error Code: 1044. Access denied for user 'root'@'10.%' to database 'abc'
Run Code Online (Sandbox Code Playgroud)

这是我曾经授予的查询

GRANT SELECT, INSERT, UPDATE ON abc.* TO 'myUser'@'10.%';
Run Code Online (Sandbox Code Playgroud)

这没有任何原因,因为当我执行“ root” @“ 10.%”的SHOW GRANTS时,这就是我得到的

GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.%' IDENTIFIED BY PASSWORD 'jklasdfksfkashdfksdfhsdlkfasdfjklasdfsjk'
Run Code Online (Sandbox Code Playgroud)

我试图再次授予所有特权,但仍然遇到相同的错误。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.%';
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)

我在这里可能做错了什么?用户'root'@'10.0.1.15'为什么不能授予其他用户特权?

mysql

0
推荐指数
1
解决办法
4674
查看次数

为什么我需要创建一个属性来检查在c#中使用一次性pastern时是否已经处理了资源?

我需要编写一个类,我想让消费者通过using(...)在C#中包装带有语句的代码来处理代码.

为此,我必须实现Microsoft的IDisposable界面.

基于Microsoft实现它的方法,我应该做这样的事情

这样的通用接口

public interface ISomeClass : IDisposable
{
     // ... some methods to include
}

public class SomeClass : ISomeClass
{
     private readonly TimeTrackerContext _context;

    private bool disposed = false;

    protected virtual void Dispose(bool disposing)
    {
        if (!this.disposed && disposing && _context != null)
        {
            _context.Dispose();

        }
        this.disposed = true;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试以正确的方式学习C#,因此我对此实现有一些疑问.

为什么我真的需要有一个属性告诉我在处理之前对象是否已被处置?

换句话说,_context在处理它之前,我不能只检查是否为null吗?像这样的东西

public class SomeClass : ISomeClass
{
    private …
Run Code Online (Sandbox Code Playgroud)

.net c# dispose idisposable

0
推荐指数
1
解决办法
104
查看次数