asp.net mvc application not working after publish - asp.net

i have a wired problem with my app.
as along as i run my app using visual studio, there is no problem but when i try to publish and run it using IIS i get the following error
[NullReferenceException: Object reference not set to an instance of an object.]
Achasoft.AchaCms.Web.RouteConfig.RegisterRoutes(RouteCollection routes) +813
Achasoft.AchaCms.Web.MvcApplication.Application_Start() +182
[HttpException (0x80004005): Object reference not set to an instance of an object.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859725
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Object reference not set to an instance of an object.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
i read some articles about Application_Start in IIS 7 but shouldnt the default (asp.net mvc application template) routing work...

Please check the publish code that all the dll related to the MVC were published. Because by default MVC dll's was not copy to the local.

You should check these:
Server features, that supports asp.net site.
Too add all deployable dependencies.
If you have database, to check connection string

Check if your Hosting provider supports Specific version of MVC you are using or they even support MVC.

Related

hosting an application with the hosting provider (shared hosting)

I have an application that is working perfect on my local machine but it gives an error when uploaded in a hosting space. I called the technical support of my hosting provider and they are not technical enough to know what the problem is, they only tell me that they do no allows full trust level.
below is the error I get when visiting my URL:
Server Error in '/' Application.
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
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:
[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Delegate.DelegateConstruct(Object target, IntPtr slot) +0
Owin.Loader.DefaultLoader..ctor(Func'3 next, Func'2 activator, IEnumerable'1 referencedAssemblies) +69
Microsoft.Owin.Host.SystemWeb.OwinBuilder.GetAppStartup() +65
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +28
System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +86
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34280
Screenshot of the error
Can anyone help me resolving this problem?
You're calling the Microsoft.Owin DLLs and those require full trust, they won't run under medium trust. If your host won't support full trust, you'll need to find an alternative to Microsoft.Owin that DOES run in medium trust, or switch hosting providers to one who DOES support full trust.
See this post Is trying to develop for Medium Trust a lost cause? for more details.

Custom Error page for failed application Initialization

I'm struggling to find a solution to the following use case.
Our sitecore analytics (DMS) db is out of control and frequently locks up causing sql to generally be unavailable, during these short intervals of errors our custom error pages that we've set up using the Custom Error node begin to fail because the application pool gets reset and sql is required inside of sitecore's initialize application pipeline. Can I get out in front of this message?
Below is the stack trace:
System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +175
Sitecore.Security.Domains.Domain.CreateAnonymousUserIfNeeded() +56
Sitecore.Pipelines.Loader.EnsureAnonymousUsers.Process(PipelineArgs args) +143
(Object , Object[] ) +80
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +191
Sitecore.Nexus.Web.HttpModule.Application_Start() +172
Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +516
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
You could try taking a look at the IIS custom errors to capture the 500 instead, that way they are a catch-all and will work if asp net falls over. You can set them either through the IIS manager or in config with the system.webServer/httpErrors elements.
From MSDN: http://www.iis.net/configreference/system.webserver/httperrors
If you have a specific error number when this happens, you can handle it in web.config to a page that isn't running out of Sitecore. I think you can also set up a default that will catch any unhandled exception.
Here's the documentaition:
https://msdn.microsoft.com/en-us/library/h0hfz6fc%28v=vs.85%29.aspx
<customErrors>
<error StatusCode="XXX" redirect="errorpage.htm" />
</customErrors>
You have a web application as opposed to a website most likely is why you're not getting the behavior you think you would.
Take a look at https://msdn.microsoft.com/en-us/library/24395wz3%28v=vs.140%29.aspx and follow the global.asax approach, which get the redirect firing in the right place in the right stack.

Request is not available in this context (local works), from web deploy

I cannot get the site to work, works fine on local, but once I web deploy it I get the error below.
Exception Details: System.Web.HttpException: Request is not available in this context
Stack Trace:
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +12964837
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12968244
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12807949
App_start:
protected void Application_Start(object sender, EventArgs e)
{
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
The site is on it's own app pool and I have also changes the app Pool from integrated to classic. Applicatiun is running, etc...
I have searched tirelessly for the last couple hours, none of the research has answered the question, I still cannot come up with a solution, does anyone have any ideas?
When in classic mode i get a "This operation requires IIS integrated pipeline mode." error.
OK, it turns out that the problems where related to database tables, when the application starts it was loading clients and role actions. There was a miss match on one of the tables, so the application was throwing an exception.
On the development database the tables where fine, but on the testing database the tables had the issue above, this is why it was hard to catch at first, but when I pointed the connection strings on development from the development database to the testing database I was able to catch and fix the issue.
Thanks for the responses.

ASP.NET Request is not available in this context

When I try to open the website, I get this problem and I have no idea whats wrong with it.
I have edited the stack trace with it
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() +8806688
labs.shared.config.CFGConstants.InitializeFromHttpContext() +42
labs.shared.config.CFGConstants..ctor() +722
labs.shared.config.CFGConstants.Get() +108
labs.site.framework.FWStateHelper.OnApplicationStart(HttpApplication app) +12
labs.site.Global.Application_Start(Object sender, EventArgs e) +5
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +2724290
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +128
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295
System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8909915
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333
You are probably doing stuff in the Application_Start event handler. In IIS 7, there is no HttpRequest available at that time, and you shouldn't depend on a request for initializing your application.
If you really need request stuff early in your application's lifespan, you need to catch the first request getting through.
You might want to include the stack trace that you seem to have cut off. The description is pretty self evident that Request couldn't be used where you tried to use it. I suspect that you have tried to access the Request object in the Application_BeginRequest handler (that I think is called before things like Session and Request are initialised. I think that Application_AcquireRequestState is the earliest that Request is available...
Turns out from the stack trace you provided that the code is in Application_Start though the same as above applies. What are you trying to do here? Can it be done at a later stage? What is it actually getting from the Request object and can that information be obtained some other way?
You'll certainly need to move your code around somehow...

Weird ASP.NET (MVC) error: "Unable to load one or more of the requested types."

I'm getting weird error and I have no idea how to resolve it. I've got an ASP.NET MVC website which works fine but once I publish it to a server I get:
"Unable to load one or more of the
requested types. Retrieve the
LoaderExceptions property for more
information."
Stack Trace:
[ReflectionTypeLoadException: Unable
to load one or more of the requested
types. Retrieve the LoaderExceptions
property for more information.]
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr
appContext, HttpContext context,
MethodInfo[] handlers) +206
System.Web.HttpApplication.InitSpecial(HttpApplicationState
state, MethodInfo[] handlers, IntPtr
appContext, HttpContext context) +188
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr
appContext, HttpContext context) +295
System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr
appContext, HttpContext context) +56
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr
appContext) +231
[HttpException (0x80004005): Unable to
load one or more of the requested
types. Retrieve the LoaderExceptions
property for more information.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext
context) +8889839
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext
context) +85
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +333
I was trying to google some solution but so far have not found anything.
The website has quite a lot of references which is most probably the cause of this problem, however I have no idea how to identify the problematic assembly.
The website runs on a subdomain, root site is also ASP.NET MVC app.
After some investigation I was able to track the problem to (Fluent) NHibernate. It was not able to initialize itself due to security constraints on the server (read Medium Trust).
First I tried to update to latest version hoping it would work in medium trust environment. Then I tried to patch it to work and then I just simply gave up and contacted my hosting provider to raise the trust level for the app.

Resources