Asp.net 如何防止OWIN处理路由

Asp.net 如何防止OWIN处理路由,asp.net,asp.net-mvc-5,owin,Asp.net,Asp.net Mvc 5,Owin,我已经为CookieAuthentication配置了一个使用Microsoft.Owin 3.0.1的ASP.NET MVC5应用程序。在我的应用程序中,我有一个路径,我想使用EssentialObjects EO.PDF库根据Razor视图生成PDF 当PDF生成过程开始时,会向服务器发出第二个请求,但该请求中不存在验证cookie。OWIN拒绝该请求并重定向到登录页面 是否可以告诉OWIN忽略某条特定路线?这是我的Startup.cs public partial class Startu

我已经为CookieAuthentication配置了一个使用Microsoft.Owin 3.0.1的ASP.NET MVC5应用程序。在我的应用程序中,我有一个路径,我想使用EssentialObjects EO.PDF库根据Razor视图生成PDF

当PDF生成过程开始时,会向服务器发出第二个请求,但该请求中不存在验证cookie。OWIN拒绝该请求并重定向到登录页面

是否可以告诉OWIN忽略某条特定路线?这是我的Startup.cs

public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        }
    }
这是由此产生的异常,似乎来自Owin:

Exception information: 
    Exception type: HttpException 
    Exception message: Server cannot append header after HTTP headers have been sent.
   at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace)
   at System.Web.HttpHeaderCollection.Set(String name, String value)
   at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key, String[] values)
   at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(String key, String[] value)
   at Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
   at Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
   at Microsoft.Owin.HeaderDictionary.AppendValues(String key, String[] values)
   at Microsoft.Owin.Infrastructure.ChunkingCookieManager.AppendResponseCookie(IOwinContext context, String key, String value, CookieOptions options)
   at Microsoft.Owin.Security.Cookies.CookieAuthenticationHandler.<ApplyResponseGrantAsync>d__f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

原来这个问题完全与我的浏览器cookies有关。一时兴起,我隐姓埋名,结果成功了。非常令人沮丧。然后我切换回我的正常窗口,删除我的cookies,重新验证,OWIN land的一切都很好

为什么会有第二个请求?这听起来像是真正的问题…我不确定PDF库是如何生成PDF响应的,但它总是导致在questionCheckout中更新相同的IIS错误。但是我同意@ErikPhilips,我会找到根本问题的根源。好的,谢谢,我会继续挖掘可能导致OWIN在上下文中没有经过身份验证的用户的情况下被访问的原因。好的。。。第二个请求是如何提出的。。我肯定某个地方有一些代码可以做到这一点?