mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-24 19:08:18 +08:00
Trying to resolve httpContext when there is no httContext
--HG-- branch : dev
This commit is contained in:
parent
3cbb532327
commit
ae11f911a5
@ -43,16 +43,23 @@ namespace Orchard.Mvc {
|
||||
}
|
||||
|
||||
static RequestContext RequestContextFactory(IComponentContext context) {
|
||||
var httpContext = context.Resolve<HttpContextBase>();
|
||||
var mvcHandler = httpContext.Handler as MvcHandler;
|
||||
if (mvcHandler != null) {
|
||||
return mvcHandler.RequestContext;
|
||||
}
|
||||
var httpContextAccessor = context.Resolve<IHttpContextAccessor>();
|
||||
var httpContext = httpContextAccessor.Current();
|
||||
if (httpContext != null) {
|
||||
|
||||
var hasRequestContext = httpContext.Handler as IHasRequestContext;
|
||||
if (hasRequestContext != null) {
|
||||
if (hasRequestContext.RequestContext != null)
|
||||
return hasRequestContext.RequestContext;
|
||||
var mvcHandler = httpContext.Handler as MvcHandler;
|
||||
if (mvcHandler != null) {
|
||||
return mvcHandler.RequestContext;
|
||||
}
|
||||
|
||||
var hasRequestContext = httpContext.Handler as IHasRequestContext;
|
||||
if (hasRequestContext != null) {
|
||||
if (hasRequestContext.RequestContext != null)
|
||||
return hasRequestContext.RequestContext;
|
||||
}
|
||||
}
|
||||
else {
|
||||
httpContext = new HttpContextPlaceholder();
|
||||
}
|
||||
|
||||
return new RequestContext(httpContext, new RouteData());
|
||||
|
Loading…
Reference in New Issue
Block a user