2012-07-10 134 views
0

我開發了一個asp.net mvc3應用程序,它在本地主機上運行良好,但是當我使用所有.dll在線託管時,它會給出錯誤ASP.NET MVC3:System.Web.HttpException:請求在此上下文中不可用

Server Error in '/' Application. 

Request is not available in this context 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Request is not available in this context 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[HttpException (0x80004005): Request is not available in this context] 
    System.Web.HttpContext.get_Request() +8828580 
    atulitbaldhama.MvcApplication.Application_Start() in D:\2012\atulitbaldhama\atulitbaldhama\atulitbaldhama\Global.asax.cs:66 

[HttpException (0x80004005): Request is not available in this context] 
    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9093225 
    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131 
    System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194 
    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339 
    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253 

[HttpException (0x80004005): Request is not available in this context] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9013676 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

我該如何解決它?我已經嘗試了很多

感謝

回答

1

是否this申請?服務器顯然是IIS7,你的本地主機可能是IIS6。

從鏈接引用提到:

這個錯誤是由於在IIS7集成管道 ,使得在Application_Start事件無法請求上下文中的設計更改。 當使用經典模式(在以前的 版本的IIS上運行時的唯一模式)時,儘管Application_Start事件始終打算作爲 應用程序中的全局和請求不可知事件,但該請求上下文曾經可用,即使 也可用一生。 儘管如此,由於ASP.NET應用程序總是通過 對應用程序的第一次請求啓動,因此通過靜態HttpContext.Current字段可以獲得請求 上下文。

1

不知道這是否有助於某人.. 但我將應用程序池設置爲經典.NET AppPool,並且錯誤消失。

馬丁

0

請在代碼中使用的

HttpContext.Current.Response.Redirect("PageName"); 

代替

Response.Redirect("PageName"); 

相關問題