小编use*_*165的帖子

Unix shell脚本找出脚本文件所在的目录?

基本上我需要使用与shell脚本文件位置相关的路径运行脚本,如何将当前目录更改为脚本文件所在的目录?

unix shell

459
推荐指数
14
解决办法
50万
查看次数

从JavaScript中的日期减去天,月,年

有没有人知道一个简单的约会方式(例如今天)和回去X天,X个月和X年?

我试过了:

var date = new Date();
$("#searchDateFrom").val((date.getMonth() -1 ) + '/' + (date.getDate() - 6) + '/' + (date.getFullYear() - 1));
Run Code Online (Sandbox Code Playgroud)

但我得到了一个负面日期,例如今天的输出是:

3/3/2015

有什么建议吗?

谢谢.

javascript

50
推荐指数
6
解决办法
8万
查看次数

回调重定向不保留会话

我有一个方案,当我使用真正的omniauth时工作得很好,但是当我用黄瓜/水豚的模拟auth运行它时失败了.

在回调中,当我这样做时sign_in @user,它成功创建用户并登录... current_user已设置.但是当我这样做时redirect_to request.env['omniauth.origin'] || '/',在接下来的行动中,current_user现在是零.

我已通过屏幕截图确认/暂停浏览器它不能使用模拟身份验证.firefox和chrome驱动程序中出现相同的错误.

知道为什么会发生这种情况吗?

/features/support/env.rb:

Cucumber::Rails::Database.javascript_strategy = :truncation
Run Code Online (Sandbox Code Playgroud)

场景:

@javascript
Scenario:
    Given I am on the home page
    When I press "Login"
    And I should see "Login with Twitter" in the selector "#login-modal"
    Given Omniauth returns a user with provider "twitter" and uid "1" and nickname "foo"    
    When I login with Twitter
    Then I should be logged in as "foo"
Run Code Online (Sandbox Code Playgroud)

步骤定义:

Given(/^Omniauth returns a user with provider "(.*?)" …
Run Code Online (Sandbox Code Playgroud)

cucumber capybara omniauth omniauth-twitter

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

如何使用自定义属性扩展IdentityUser

我正在使用asp.net Identity 2.0登录我的网站,其中身份验证详细信息存储在SQL数据库中.Asp.net Identity已经以标准方式实现,可以在许多在线教程中找到.

ApplicationUserIdentityModels已经扩展到包括自定义属性:

public class ApplicationUser : IdentityUser
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
    {
       CookieAuthenticationOptions.AuthenticationType
       var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
       return userIdentity;
    }
    //My extended property
    public string Code { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我注册一个新用户时,我传递了Code自定义属性,RegisterBindingModel但我不知道如何将此自定义属性插入WebUsers表.

我做了如下,但实际上并没有将这个属性与用户名和密码一起插入到表中.

var user = new ApplicationUser() { UserName = userName, Email = model.Email, Code=model.Code };
Run Code Online (Sandbox Code Playgroud)

而整个功能:

[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var …
Run Code Online (Sandbox Code Playgroud)

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

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

我可以在ASP.Net项目的代码隐藏中使用JSON.Stringify

在ASP.NET项目(MVP模式)的代码隐藏中,我在其中一个演示者中获得了一个字符串,其中包含一些看起来像JSON文件内容的字符串.

然后我用该字符串设置视图的一个属性 - 分配给演示者.

在视图中,字符串显示在TextBox中,但它看起来不太好,因为它不是使用换行符和换行符构造的.我知道有一个名为Stringify的JSON函数可以使这些字符串变得漂亮.

我可以在代码隐藏中调用JSON函数吗?每个例子我在演示者中设置视图的属性?

所以我在演示者中设置它:

this.view.ContentAsJson = GetContentAsJson(uuid);
Run Code Online (Sandbox Code Playgroud)

这是我想做的,如果可能的话:

this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
Run Code Online (Sandbox Code Playgroud)

GetContentAsJson 是一个创建并返回JSON字符串的函数.

这是我的看法:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
    <p>
        <asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

这是视图中获取字符串的属性:

public string ContentAsJson
{
   set
   {
       if (!string.IsNullOrEmpty(value))
       {
            TbContentJson.Text = value;
       }
       else
       {
            TbContentJson.Text = "";
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net json

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

查询字符串参数中的斜杠?

如何将文件路径作为查询字符串参数发送?

这是我的字符串参数:

//domain/documents/Pdf/1234.pdf

我试过了:

    [HttpPost]
    [Route("documents/print/{filePath*}")]
    public string PrintDocuments([FromBody] string[] docs,string filePath)
    {
       .....
    }
Run Code Online (Sandbox Code Playgroud)

但这不起作用,我想是因为参数开头的双斜线.

任何的想法?

c# asp.net-mvc url-routing

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

如何在React中引用本地svg?

以下代码编译得很好,但图标没有显示:

在此输入图像描述

Icon.jsx 零件:

import React from 'react';
import { css } from 'emotion';

import ArrowRight from "./arrow-right.svg";

export const iconTypes = {
    arrowRight: 'ARROW_RIGHT',
   // arrowLeft: 'ARROW_LEFT',
}

const iconSrc = {
    ARROW_RIGHT: ArrowRight,
   // ARROW_LEFT: ArrowLeft,
}


export default function Icon({ type }) {
    return (
        <div>
            <img src={iconSrc[type]}/>
        </div>
    )
};
Run Code Online (Sandbox Code Playgroud)

在浏览器中,请求如下所示:

 http://localhost:9001/%22data:image/svg+xml,%3Csvg%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20width='512'%20height='512'%20viewBox='0%200%20512%20512'%3E%20%3Ctitle%3E%3C/title%3E%20%3Cg%20id='icomoon-ignore'%3E%20%3C/g%3E%20%3Cpath%20d='M310.627%20438.627l160-160c12.497-12.496%2012.497-32.758%200-45.255l-160-160c-12.497-12.496-32.758-12.496-45.255%200s-12.497%2032.758%200%2045.255l105.373%20105.373h-306.745c-17.673%200-32%2014.327-32%2032s14.327%2032%2032%2032h306.745l-105.373%20105.373c-6.248%206.248-9.372%2014.438-9.372%2022.627s3.124%2016.379%209.372%2022.627c12.497%2012.497%2032.758%2012.497%2045.255%200z'%3E%3C/path%3E%20%3C/svg%3E%22 
Run Code Online (Sandbox Code Playgroud)

Icon.jsx 故事:

import { action } from "@storybook/addon-actions"; 
import Icon from "../components/Icon/Index"; 
import { iconTypes } from "../components/Icon/Index";


    storiesOf("Icon", module)
        .add("with text", () => ( …
Run Code Online (Sandbox Code Playgroud)

reactjs

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

如何将动态对象转换为JSON字符串c#?

我从第三方库获得以下动态对象:

IOrderStore os = ss.GetService<IOrderStore>();
IOrderInfo search = os.Orders.Where(t => t.Number == "test").FirstOrDefault();
IOrder orderFound = os.OpenOrder(search, true);

dynamic order = (dynamic)orderFound;
dynamic requirements = order.Title.Commitments[0].Requirements;
Run Code Online (Sandbox Code Playgroud)

我需要将其解析为JSON字符串.

我试过这个(使用JSON.net):

string jsonString = JsonConvert.SerializeObject(requirements);
return jsonString;
Run Code Online (Sandbox Code Playgroud)

但是我得到了一个看似已损坏的JSON字符串,如下所示:

[{ "$ ID": "1"},{ "$ ID": "2"},{ "$ ID": "3"},{ "$ ID": "4"},{ "$ ID" : "5"},{ "$ ID": "6"},{ "$ ID": "7"},{ "$ ID": "8"},{ "$ ID": "9"}, { "$ ID": "10"},{ "$ ID": "11"},{ "$ ID": "12"},{ "$ ID": "13"},{ "$ ID": "14"},{ …

c# serialization json

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

使用MemoryStream和ZipArchive将zip文件返回到asp.net web api中的客户端

我试图使用以下代码将zip文件从asp.net web api返回给客户端:

private byte[] CreateZip(string data)
{
    using (var ms = new MemoryStream())
    {
        using (var ar = new ZipArchive(ms, ZipArchiveMode.Create, true))
        {
            var file = archive.CreateEntry("file.html");

            using (var entryStream = file.Open())
            using (var sw = new StreamWriter(entryStream))
            {
                sw .Write(value);
            }
        }
        return memoryStream.ToArray();
    }
}

public HttpResponseMessage Post([FromBody] string data)
{
    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
    result.Content = new ByteArrayContent(CreateZip(data));
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip, application/octet-stream");
    return result;
}
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我收到以下错误:

ExceptionMessage":"值'application/zip,application/octet-stream'的格式无效."

这是JS代码:

$.ajax({
  type: "POST",
  url: url,
  data: …
Run Code Online (Sandbox Code Playgroud)

c# ajax memorystream ziparchive asp.net-web-api

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

防止没有确认电子邮件的用户登录ASP.NET MVC Web API身份(OWIN安全性)

我有一个MVC和一个Web API项目,使用ASP.NET MVC Web API身份(OWIN安全性)进行身份验证.

我在Register功能正常的函数中添加了电子邮件确认,但我不确定如何emailConfirmed = true在登录之前检查是否因为Web API标识上没有显式的登录功能,这是隐含的.

我知道微软有充分的理由深度封装授权功能,但是没有办法实现这一目标吗?

请指教.

这是我的注册功能:

[AllowAnonymous]
[Route("Register")]
 public async Task<IHttpActionResult> Register(RegisterBindingModel model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

        IdentityResult result = await UserManager.CreateAsync(user, model.Password);

        if (!result.Succeeded)
        {
            return GetErrorResult(result);
        }

        try
        {
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));

            var email …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc login asp.net-web-api asp.net-identity

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