当我将下面的行添加到我的Startup类时,我得到以下异常.这是一个从mono(Ubuntu)运行的自托管exe.它在Windows中工作正常.我已经将它缩小了UseCookieAuthentication调用范围.我可以毫无问题地实例化选项.知道这里发生了什么吗?我有aspnet Identity工作和EF6/MySql.
app.UseCookieAuthentication(new CookieAuthenticationOptions());
Run Code Online (Sandbox Code Playgroud)
未处理的异常:System.Reflection.TargetInvocationException:调用的目标抛出了异常.---> System.TypeLoadException:无法从程序集"Microsoft.Owin.Security,Version = 2.1.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"加载类型"Microsoft.Owin.Security.DataProtection.DpapiDataProtector".在Microsoft.Owin.Security.CreateDataProtction.AppBuilderExtensions.CreateDataProtector(Owin.IAppBuilder,string [])<0x00052> at Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor(Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft. Owin.Security.Cookies.CookieAuthenticationOptions)<0x00223> at(wrapper dynamic-method)object.lambda_method(System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00048>在(包装管理到本机)System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,对象,对象[],System.Exception的&)<0x00067>在System.Reflection.MonoMethod.Invoke(对象, System.Reflection.BindingFlags,System.Reflection.Binder,object [],System.Globalization.CultureInfo)<0x000d7>
---内部异常堆栈跟踪结束---在System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object []参数,System.Globalization.CultureInfo文化) [0x00000] in:0在System.Reflection.MethodBase.Invoke(System.Object obj,System.Object [] parameters)[0x00000] in:0 at System.Delegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0在System.MulticastDelegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0 at System.Delegate.DynamicInvoke(System.Object [] args)[0x00000] in:0 at Microsoft.Owin.Builder. AppBuilder.BuildInternal(System.Type的签名)[0x00000]中:0在Microsoft.Owin.Builder.AppBuilder.Build(System.Type的返回类型)[0x00000]中:0在Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create( IAppBuilder构建器)[0x00000] in:0 at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(Microsoft.Owin.Hosting.Engine.StartContext context)[0x00000] in:0 at Micros ofO.Owin.Hosting.Engine.HostingEngine.Start(Microsoft.Owin.Hosting.Engine.StartContext context)[0x00000] in:0 at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(Microsoft.Owin.HostingStartOptions options) )[0x00000]中:0在Microsoft.Owin.Hosting.Starter.HostingStarter.Start(Microsoft.Owin.Hosting.StartOptions选项)[0x00000]中:0在Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider的服务,微软.Owin.Hosting.StartOptions选项)[0x00000] in:0 at Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0 at Microsoft.Owin.Hosting.WebApp.Start [Startup](Microsoft.Owin.Hosting.StartOptions选项)[0x00000] in:0,Microsoft.Owin.Hosting.WebApp.Start [Startup](System.String url)[0x00000] in:0,HelloWorldNancy.Program.Main (System.String [] args)[0x00000] in:0 [错误]致命未处理异常:System.Reflection.TargetInvocationException:调用目标抛出了异常.---> …
我正在尝试执行经过身份验证的Web api请求,该请求不会重置身份验证Cookie超时.在MVC世界中,我将通过从响应中删除FormsAuthenication cookie来实现此目的:
Response.Cookies.Remove(System.Web.Security.FormsAuthentication.FormsCookieName);
Run Code Online (Sandbox Code Playgroud)
在Web API 2中,我编写了一个自定义的IHttpActionResult,我从响应中删除了Set-Cookie标头.但是,这不是删除标头,因为在为使用此操作结果的请求更新auth cookie时,我仍然会看到Set-Cookie标头.
这是自定义IHttpActionResult:
public class NonAuthResetResult<T> : IHttpActionResult where T: class
{
private HttpRequestMessage _request;
private T _body;
public NonAuthResetResult(HttpRequestMessage request, T body)
{
_request = request;
_body = body;
}
public string Message { get; private set; }
public HttpRequestMessage Request { get; private set; }
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
var msg = _request.CreateResponse(_body);
msg.Headers.Remove("Set-Cookie");
return Task.FromResult(msg);
}
}
Run Code Online (Sandbox Code Playgroud)
如何编辑Web API 2中的响应标头,因为这不起作用.
我正在努力使用EPPlus将一些信息导出到excel中,并且我在使用公式的总计行上遇到了绊脚石.当我打开文件时,只计算第一个公式,而其他公式仅在我进入和离开公式单元格时计算.下面是构建表的代码和结果.希望有人可以提供一些有关如何解决此问题的见解.
private void BuildSalesTable(string label, ISalesTable table)
{
var sheet = ExcelPackage.Workbook.Worksheets.Add(string.Format("Sales{0}", label));
//table header
//BuildHeader(startRow, 2, startRow, 9, string.Format("Sales Tons - {0}", label));
//table lables
sheet.Cells[1, 2].Value = "Joist Qtd";
sheet.Cells[1, 3].Value = "PP/Ton";
sheet.Cells[1, 4].Value = "Deck Qtd";
sheet.Cells[1, 5].Value = "PP/Ton";
sheet.Cells[1, 6].Value = "Joist Sold";
sheet.Cells[1, 7].Value = "PP/Ton";
sheet.Cells[1, 8].Value = "Deck Sold";
sheet.Cells[1, 9].Value = "PP/Ton";
for (int i = 0; i < table.Rows.Count; i++)
{
var row = 2 + i;
//every other …Run Code Online (Sandbox Code Playgroud) Context.User在我的集线器中为空,我不知道为什么.
的Starup:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
AuthenticationMode = AuthenticationMode.Passive,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(5),
regenerateIdentity:
(manager, user) =>
user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie))
}
});
app.MapSignalR();
ConfigureWebApi(app);
app.UseNancy();
Run Code Online (Sandbox Code Playgroud)
毂:
public class TestHub : Hub
{
public void Hello()
{
Clients.All.hello(DateTime.Now.ToString("F"));
}
public void CurrentUser()
{
var user = Context.User;
Clients.Caller.currentUser(user.Identity);
}
}
Run Code Online (Sandbox Code Playgroud)
CurrentUser方法抛出异常,因为Context.User为null.我不确定哪些额外信息会有所帮助.我想我可以从当前的owin语境中得到这个,但是我没有办法得到这个.我试图创建一个IAuthorizeHubConnection属性,但我找不到从IRquest对象获取当前owin上下文的方法.我可以做一个新的.