ASP.NET MVC site as a virtual directory under Web Pages site? - asp.net

I have a main site, example.com, implemented in ASP.NET Web Pages and deployed on Azure Websites. I then have another site which is implemented in ASP.NET MVC which I'd like to deploy as example.com/subsite. I have created a virtual directory using the Azure Portal but when I deploy my files there, I get this very nasty error:
An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
I don't get any additional info, there is no YSOD, there are no failed request tracing logs when I enable them, just nothing.
I'm just guessing but probably my web.configs are somehow colliding. For example, under some circumstances, my request to /subsite/something gets caught by HTTP 500 error handler in the super site.
I need some very general advice here; is it at all possible to deploy two ASP.NET apps with their own web.config's in the same site, just using the virtual directories? If it is possible, are there some typical gotchas that I am possibly falling for?

I could solve similar creating a virtual application inside a wordpress website. In my case, I've put the following configuration in wordpress's web.config :
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>

Related

Server Error in '/admin' Application....An application error occurred on the server

I have 2 projects in my solution (ASP.NET MVC 5), one for the client and one for the admin. Both projects are running fine locally. But when I publish the admin project (which is located in the path: root/admin in my hosting) I'm getting the next error:
An application error occurred on the server. The current custom error
settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could,
however, be viewed by browsers running on the local server machine.
Something to know, I have added:
<system.web>
<customErrors mode="Off"/>
</system.web>
But i don't see any specific error and also I have configured the virtual directory root/admin as an application in IIS.
I know this is a common error but I don't see any solution like this one: Server Error in '/' Application. ASP.NET
The entry "Data.Models.ApplicationDbContext" has already been added.
That along with the Source File being the web.config, I'd look to see if that ApplicationDbContext is in the web.config twice and causing an issue in loading the application.
In the error message above is this reference:
e:\Web\deliver4\admin\web.config line: 18
So, what are around line 18 in that web.config file?
I solved the problem with this https://stackoverflow.com/a/6679286/2958543
<remove name="Data.Models.ApplicationDbContext" />
after my connectionString.

ASP.NET 5 custom error page does not render on Azure Website

I have a ASP.NET 5 site that I want to add custom error pages to. I'm used to adding entries in the web.config (from ASP.NET 4 days) but I want to use the new approach in ASP.NET 5. So I have the following in my Startup.cs class:
if (env.IsEnvironment("Development"))
{
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
app.UseStatusCodePagesWithReExecute("/Home/Error");
app.UseErrorHandler("/Home/Error");
}
When I run locally using kestral my error page is displayed properly. However, when I deploy to Azure I get the very generic white error page when I try to test 404 errors:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I tried implementing this answer in my web.config and it does not resolve my issue:
https://stackoverflow.com/a/29539669/8320
This is the relevant part of my web.config:
<system.web>
<customErrors mode="Off" />
</system.web>
I have also ensured that ASPNET_ENV="Production" in the Configure / App Settings section of the Azure Website.
Any ideas? If I can provide more info let me know.
IIS is a tricky beast and we're still working through this in ASP.NET 5. When you run on IIS, we run through the middleware pipeline and then call back into IIS native modules if nothing handled the request. When you get a 404 that was un-handled by any middleware, it will re-enter the IIS pipeline and trigger IIS specific error pages. The UseStatusCodePagesWithReExecute middleware still runs, but by then, IIS has already sent the headers and body to the client (browser in this case).

404 handling - Difference between local ASP.Net (C# 4) and remote server (live)

I'm facing a problem:
I do want to do URL rewriting with ASP.Net
It works perfectly using my local settings, but once on the server it doesn't work as expected.
Local
Request to /unavailable-file.aspx gets well in the Application_Error (Global.asax.cs) and then is being redirected to /404.aspx
Request to /unavailable-random-folder or any other file gets well in the Application_Error (Global.asax.cs) and then is being redirected to /404.aspx
Remote
Any request to a .aspx file WILL be catched in the Application_Error
Every other request (.jpg, folder, etc...) will NOT be catched at all and thrown into the default 404 page error
My problem:
Yesterday I was installing my new website to the server and I saw that Application_BeginRequest was not even fired AT ALL on my server, when it was every time (for every file or folder requested) in my local computer (with visual studio).
I had to create an HttpModule and now I am successfully getting the events firing... but not for non .aspx requests.
Everything seems to be bound on the URL : when it ends with .aspx it's correctly managed and when it's not, it's just not managed at all.
What should I do to catch every Application_BeginRequest even for non aspx page?
I have that in my web.config to try to force the 404 errors into my page:
<customErrors mode="On"
defaultRedirect="404.aspx">
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
But as I said, as long as it's not a request ending with .aspx it's not being redirected and I get the default ASP.Net 404 error.
(My host is "reliablesite" if it can help, and I have the settings of the 404 errors pointing to my 404.aspx page inside the manager (shared hosting), it does not change anything)
I wish everything would work as in local mode.
If you have any tip on how to resolve that problem let me know.
In the development web server every request is handled by the aspx engine, as that's all there is. In the live server different file types are handled by different engines.
To make the live server use the aspx engine for every request you have to change the configuration in IIS for the web site.
Related: ASP.net web.config doesn't catch all 404's
The solution of this problem is given here when you have a shared environment:
Active the ASP.Net Integrated Pipeline in your shared environment settings (a thing that is available since IIS 7)
Add this to the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="RedirectHttpModule" type="RedirectHttpModule" />
</modules>
</system.webServer>
Where RedirectHttpModule is a custom module handling Application_BeginRequest for example.
The "runAllManagedModulesForAllRequests" means that all managed modules will be invoked for all requests to web application.

ASPX page within a .aspx page with iframe throws 500.23 error

I'm trying to embed a ChartModule.aspx page within a Default.aspx page using an iframe.
The ChartModule has a button event which updates a chart. The ChartModule has its own ChartsModule.cs.
I'm getting this error:
HTTP Error 500.23 - Internal Server Error An ASP.NET setting has been
detected that does not apply in Integrated managed pipeline mode.Most
likely causes:
•This application defines configuration in the system.web/httpHandlers
section. Things you can try: •Migrate the configuration to the
system.webServer/handlers section. You can do so manually or by using
AppCmd from the command line. For example, from the IIS Express
install directory, run appcmd migrate config "Default Web Site/".
Using AppCmd to migrate your application will enable it to work in
Integrated mode. It will continue to work in Classic mode and on
previous versions of IIS. •If you are certain that it is OK to ignore
this error, it can be disabled by setting
system.webServer/validation#validateIntegratedModeConfiguration to
false. •Alternatively, switch the application to a Classic mode
application pool. For example, from the IIS Express install directory,
run appcmd set app "Default Web Site/"
/applicationPool:"Clr4ClassicAppPool". Only do this if you are unable
to migrate your application.
Detailed Error Information: Module ConfigurationValidationModule
Notification BeginRequest Handler
PageHandlerFactory-Integrated-4.0 Error Code 0x80070032 Requested
URL http://localhost:4161/Default.aspx Physical Path
C:\Documents and
Settings\singhm\Desktop\Temp\Trial2\Trial2\Default.aspx Logon Method
Not yet determined Logon User Not yet determined Request Tracing
Directory
Why is this?
While this may not answer your question directly, here is a thought:
If you have the option, consider turning ChartModule.aspx into a UserControl (ascx), which acts just like another "page" (same lifecycle, its own codebehind file, etc) but integrates more cleanly into an existing aspx page. The above link should be a good introduction to creating and using UserControls.
The error message contains a clue to the solution:
setting system.webServer/validation#validateIntegratedModeConfiguration to false
So make sure the following is present in your web.config:
<validation validateIntegratedModeConfiguration="false"/>
For example:
<configuration>
<!-- your existing settings -->
<system.webServer>
<!-- Add this to here.... -->
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
IIS 7 and ASP.NET are quite helpful these days with regard to to error messages and hints contained therein so you should take the time to read them.
I would really recommend using a usercontrol page instead of iframes in asp.net this way you can bind that usercontrol by doing
public override DataBind()
in that you can pass anything into that usercontrol page like refresh data, load certain data, etc..

httpModule for 404

I've created an httpModule to handle URL remappings, and it works great on my test system. A request for www.mydomain.com/Some_Fancy_URL gets rewritten to www.mydomain.com/some.aspx?fancy=23 and so on.
When I deploy to the actual web site, I'm getting the default IIS 404 page though.
After doing some research online, it would seem that I need to setup "Wildcard Mapping" in IIS 6 to get the request past IIS and in to my httpModule. The problem is that the site is hosted on a shared server, so it may not be possible to get the ISP to make that change.
My question is, can't I use an httpHandler to tell IIS how I want these requests handled? For example:
<httpHandlers>
<add path="*.aspx" verb="GET,POST" type="System.Web.UI.PageHandlerFactory" validate="false"/>
</httpHandlers>
It would seem like adding this to my Web.Config should tell IIS to stop validating the existence of .aspx files, and just pass the request along for me to process. It doesn't work though.
Any suggestions?
The problem with IIS 6 and ASP.NET is that they're aren't integrated. IIS needs to be told about ASP.NET via script mappings (.aspx, .asmx, wildcard and so on).
None of your web.config configuration settings will influence IIS because web.config is there to configure ASP.NET's behaviour, not IIS. IIS has no knowledge of web.config.
Unless you can hand off a request to the ASP.NET pipeline (via a script map) nothing will happen and all your web.config settings will be ignored.
With IIS 7 the story is quite different. In IIS7, ASP.NET and IIS are closely integrated and share the same pipeline thus permitting you to achieve the result you're looking for.
The alternative may be to find out if your hoster runs a URL rewriter such as ISAPI_Rewrite on their servers. That way you could rewrite urls without having to map a wildcard scriptmap to IIS6.
Through some trial and error, along with more web searches, I found a solution. It essentially parallels Kev's answer.
IIS won't treat a request as .NET unless it has a known file extension (.aspx, .ascx, etc.). When I send along something like www.mydomain.com/anything it looks for a file or folder named "anything", and when it doesn't find one, it just drops off to the default IIS 404 handler.
That's where I took over. I changed IIS 6 to forward 404 problems to /404.aspx. I then created that page with a generic "Your file wasn't found" message in the same style as my web site.
Here's the good part: Now that IIS is sending 404's to a .NET page, the custom httpModule I created is getting fired. The request is for 404.aspx, but IIS is nice enough to also append the original URL as well. You get something like:
www.mydomain.com/404.aspx?404;http://www.mydomain.com/anything
This allows me to parse the request in the httpModule, and rewrite as needed!

Resources