使用dnx运行我的ASP.NET核心应用程序我能够从命令行设置环境变量,然后像这样运行它:
set ASPNET_ENV = Production
dnx web
Run Code Online (Sandbox Code Playgroud)
在1.0中使用相同的方法:
set ASPNETCORE_ENVIRONMENT = Production
dotnet run
Run Code Online (Sandbox Code Playgroud)
不起作用 - 该应用程序似乎无法读取环境变量.
Console.WriteLine(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
Run Code Online (Sandbox Code Playgroud)
返回null
我错过了什么?
在我的ASP.NET Core MVC应用程序中,身份验证cookie的生命周期设置为"会话",因此它会一直持续到我关闭浏览器为止.我使用MVC的默认身份验证方案:
app.UseIdentity();
Run Code Online (Sandbox Code Playgroud)
如何延长cookie的生命周期?
我有一个ASP.NET Core应用程序,我想使用RabbitMQ消息.
我已成功在命令行应用程序中设置发布者和使用者,但我不确定如何在Web应用程序中正确设置它.
我正在考虑初始化它Startup.cs,但当然一旦启动完成它就会死掉.
如何从Web应用程序以正确的方式初始化消费者?
将我的ASP.NET Core项目升级到2.0后,尝试访问受保护的端点不再返回401,而是重定向到(不存在的)端点以尝试让用户进行身份验证.
所需的行为是应用程序只是返回401.以前我会AutomaticChallenge = false在配置身份验证时设置,但根据这篇文章,设置不再相关(实际上它不再存在).
我的身份验证配置如下:
Startup.cs.ConfigureServices():
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(o =>
                {
                    o.Cookie.Name = options.CookieName;
                    o.Cookie.Domain = options.CookieDomain;
                    o.SlidingExpiration = true;
                    o.ExpireTimeSpan = options.CookieLifetime;
                    o.TicketDataFormat = ticketFormat;
                    o.CookieManager = new CustomChunkingCookieManager();
                });
Run Code Online (Sandbox Code Playgroud)
配置():
app.UseAuthentication();
Run Code Online (Sandbox Code Playgroud)
如何禁用自动质询,以便在用户未经过身份验证时应用程序返回401?
我正在尝试使用gulp在我的JavaScript上运行babel-preset-es2015,但它甚至需要一行代码.我最初尝试使用大约700 loc的脚本包,然后使用1行的虚拟脚本.第一种情况需要大约9s - 1行我需要8.38s.
这是我的确切设置:
的package.json:
{
    "devDependencies": {
        "gulp": "^3.9.0",
        "gulp-babel": "^6.1.1",
        "babel": "^6.3.26",
        "babel-preset-es2015": "^6.3.13"
    }, 
   "babel": {
       "presets": [ "es2015" ]
    }
}
Run Code Online (Sandbox Code Playgroud)
gulpfile.js:
gulp.task('js', function () {
    return gulp.src('dummyscript.js')
      .pipe(concat('site.bundle.js'))   
      .pipe(babel())  
      .pipe(gulp.dest(paths.dest.scripts));
});
Run Code Online (Sandbox Code Playgroud)
dummy.js:
console.log('dummy script');
Run Code Online (Sandbox Code Playgroud)
我正在运行节点v4.2.4和npm v2.14.12.
其他操作如gulp-react和gulp-uglify都需要大约180ms的组合.
到底是怎么回事?
我使用最新的SendGrid .NET包(8.0.3)从我的ASP.NET Core Web应用程序发送电子邮件:
public Task SendEmailAsync(string email, string subject, string message)
{
    return Send(email, subject, message);
}
async Task Send(string email, string subject, string message)
{
    dynamic sg = new SendGridAPIClient(_apiKey);
    var from = new Email("noreply@my.domain", "My Name");
    var to = new Email(email);
    var content = new Content("text/html", message);
    var mail = new Mail(from, subject, to, content);
    await sg.client.mail.send.post(requestBody: mail.Get());
}
Run Code Online (Sandbox Code Playgroud)
它在本地工作,但在Azure App Service实例上运行时,邮件无法通过.
代码运行良好,没有任何例外,所以我几乎无法使用,但我认为它可能是某种防火墙问题.
有没有人遇到类似的问题?我该如何调试呢?
我正在尝试创建自己的 AuthenticationHandler 并与 cookie 身份验证一起使用:
services.AddAuthentication(options =>
  {
  options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  options.DefaultChallengeScheme = MyAuth.Scheme;
  })
  .AddCookie()
  .AddScheme<MyAuthenticationOptions, MyAuthenticationHandler>(MyAuth.Scheme, "My auth scheme", options => { });
Run Code Online (Sandbox Code Playgroud)
.
public MyAuthenticationHandler(...) : base(...) {}
    protected override Task<AuthenticateResult> HandleAuthenticateAsync()
    {
        throw new NotImplementedException();  
    }    
    protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
    {                     
        var myUser = await DoAuth();
        if (!myUser.IsAuthenticated)
        {
            if (Context.Request.Query.ContainsKey("isRedirectedFromSSO"))
            {
                Context.Response.Redirect("/unauthorized");
                return;
            }
            else
            {
                Context.Response.Redirect("url to sso");
                return;
            }              
        }    
        var claims = new List<Claim>
        {
            new Claim(ClaimTypes.NameIdentifier, …Run Code Online (Sandbox Code Playgroud) 我使用ASP .NET Core RC1与Facebook身份验证和silding窗口cookie过期设置如下:
app.UseIdentity();
app.UseFacebookAuthentication();
Run Code Online (Sandbox Code Playgroud)
和
services.AddIdentity<ApplicationUser, IdentityRole>((options =>
{
    options.Cookies.ApplicationCookie.CookieName = "myauthcookie";
    options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(5);
    options.Cookies.ApplicationCookie.SlidingExpiration = true;
}))
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
这在用户首次登录时工作正常 - cookie过期设置正确.但是,当用户返回页面时,cookie的到期时间设置为"会话",因此实际上用户必须重新验证每次其他访问.
为什么会这样?我没有正确配置吗?
更新:我现在已经完成了一些没有SlidingExpiration的测试,问题仍然存在.返回页面后,cookie的到期时间将更改为"会话".我正在使用Chrome.
另外,我没有在https上运行.这可能是一个因素吗?
我们最近升级到RC2的ASP.NET核心应用程序.在升级之前一切都很好,升级后一切都在Dev和Staging环境中工作,但在Production中,应用程序对每个未由MVC端点处理的请求作出502响应:
502 - Web服务器在充当网关或代理服务器时收到无效响应. 您正在查找的页面存在问题,无法显示.当Web服务器(充当网关或代理)与上游内容服务器联系时,它从内容服务器收到无效响应.
这意味着,例如https://www.myapp.com/somenonexistingroute返回502而不是404,而对现有端点的调用工作正常.
问题是我们在跨源上下文中使用应用程序,因此我们需要选项请求(预检队列请求)才能工作,并且它们也会响应502.
所有环境都运行Windows Server 2012,并安装了IIS 8.5和ASP.NET Core平台处理程序.
到底是怎么回事?
更新
经过一些调试后,我们发现这可能是由框架中的错误引起的.我们创建了一个GitHub问题
我有以下文件:
自动建议组件.tsx:
import * as React from 'react';
interface AutosuggestProps {
    ...
}    
interface AutosuggestState {
   ...
}
export default class Autosuggest extends React.Component<AutosuggestProps, AutosuggestState> {
    ...
}
Run Code Online (Sandbox Code Playgroud)
我想在 ConsumerComponent.tsx 中导入这样的 Autosuggest 组件:
import Autosuggest = Components.AutoSuggest;
Run Code Online (Sandbox Code Playgroud)
如何导出 AutosuggestComponent.tsx 才能完成这项工作?
我尝试创建一个 Autosuggest.ts,如下所示:
import AutosuggestComponent from './AutosuggestComponent';
namespace Components {
    export const Autosuggest = AutosuggestComponent;
}
Run Code Online (Sandbox Code Playgroud)
这是行不通的。然后 ConsumerComponent 无法找到命名空间“Components”。然而,这有效:
// import AutosuggestComponent from './AutosuggestComponent';
namespace Components {
    export const Autosuggest = { dummyValue: "test" }
}
Run Code Online (Sandbox Code Playgroud)
一旦我注释掉导入,ConsumerComponent 就能够找到名称空间。为什么?
有什么办法可以解决这个问题吗?
asp.net-core ×7
c# ×5
asp.net ×4
.net-core ×1
asp.net-mvc ×1
azure ×1
babeljs ×1
gulp ×1
iis ×1
javascript ×1
node.js ×1
rabbitmq ×1
reactjs ×1
security ×1
sendgrid ×1
typescript ×1