404 error encountered when requesting a classic asp page in MVC3 - asp.net-mvc-3

I am converting a classic asp application to ASP.NET MVC3.
I have following route mappings in the global.asax:
routes.MapRoute("LogOn", "Scripts/Logon", New With {.controller = "Account", .action = "Logon"})
routes.MapRoute("LogOnASP", "Scripts/Logon.asp", New With {.controller = "Account", .action = "Logon"})
routes.MapRoute("LogOnASPX", "Scripts/Logon.aspx", New With {.controller = "Account", .action = "Logon"})
Neither logon.asp nor logon.aspX exist in the folder “Scripts”. But only logon.asp renders the 404 error. It seems that IIS checks if the logon.asp exists and reports 404 if no such a file.
How do I configure the IIS settings to allow an asp url to pass through?
I feel confused that my localhost IIS (Windows 7 64-bits), IIS 7.5) doesn’t render any error when I use the Logon.asp in a url. The error is only rendered in the demo server (IIS 7.5 on Windows 2008 R2 server).

Related

ASP.NET Core in Docker /app/Views/Email not found

I have an ASP.NET Core and I am using template to sent email notification for user registration and reset password. Everything is working fine when I run the application on localhost, but when I build the image and run in a Linux Ubuntu Server I get the error /app/Views/Email not found
This is how I a getting the view:
var razorPage = GetRazorPage("Views/Email");
private RazorLightEngine GetRazorPage(string view)
{
string currentDirectory = Directory.GetCurrentDirectory();
var fullPath = Path.Combine(currentDirectory, view);
return new RazorLightEngineBuilder().UseFilesystemProject(fullPath).UseMemoryCachingProvider().Build();
}
The problem was that the file was not available in Docker. I modify the file properties and it solved the issue.

ASP.NET MVC add/remove IIS app name/alias from URL dynamically

Because of the IIS 6.1 settings, every app that's being deployed has an alias and that has an impact on the URL. In Visual Studio's development server, the URL looks like this:
http://localhost:27019/controller/action
But after being deployed to IIS:
http://servername/appname/controller/action
as you can see there is an appname added to the URL. All the Ajax calls become incorrect after deployment. I have to create an isIIS variable and manually assign a value to it in order to make it work:
var isIIS = true; // set to false if runs locally;
window.appAlias = (isIIS) ? '/'+window.location.href.split('/')[3] : '';
And in my Ajax call:
$.post( window.appAlias + webUrl, {} , callback );
same thing with GET calls, I have to prepend the window.appAlias. Is there a way to dynamically detect whether the server is IIS or Visual Studio Development Server? I understand the #Uri.Content("~/controller/action") but I am not writing my JavaScript on the Razor view.
I am using Visual Studio 2012, target framework .NET 4.5, MVC 4 and jQuery 1.9.2 for development. The IIS application pool has .NET 4.0.
Edit
Here is my temporary solution: to add global values in _Layout.cshtml:
Object.assign({
action1: '#Url.Content("~/controller/action1")',
action2: '#Url.Content("~/controller/action2")'
}, window);

How to create a custom Maintenance page returning 503 for Azure?

I'm trying to set up a custom Maintenance page on MVC 3 but specifically on Azure. Basically to keep it SEO friendly i need to return a 503 (Service Unavailable). All my other custom error pages work in Azure (eg 404) following the usual
<customErrors mode="On">
<error statusCode="404" redirect="404.htm"/>
<error statusCode="503" redirect="503.htm"/>
</customErrors>
The 404 page works but the 503 is not followed and i simply get an ugly service unavailable page. I have the 500 error working fine through error.cshtml and the standard HandleErrorAttribute.
I even try returning my own ActionResult from an ActionFilter by using the following
public class SiteDownForTestingResult : ActionResult
{
public SiteDownForTestingResult() : base()
{
}
public override void ExecuteResult(ControllerContext context)
{
var path = System.Web.Hosting.HostingEnvironment.MapPath("~/app_testing.htm");
var response = context.HttpContext.Response;
response.Clear();
response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
response.StatusDescription = "Service Unavailable.";
response.WriteFile(path);
response.End();
}
}
were app_testing is my custom page, and then setting the filterContext.Result = new SiteDownForTestingResult(); from OnActionExecuting of an ActionFilter and still i'm greeted by the plain 503 'service unavailable' page
Is this something to do with application.config on Azure locking something or other i don't know about. This works fine on IIS7 and my local box, but the Emulator and Cloud both give no joy.
Any help would be appreciated.
Based on my understanding custom 503 error is generated directly from https.sys mostly when app pool is not available. And now when there is no app pool none of your setting is going to work at your custom error settings will be specific to app pool. Also most of the search engine depend on 503 error code in return so display search result properly and that's why customization of this error is not typically done at application level.
As you referenced Windows Azure Emulator, I believe you are using Windows Azure Web Role. With Windows Azure Web Role you can customize IIS with AppCmd.exe in a StartUp task, which is your maximum level of customization. You can not reach HTTP.sys level of customization in Windows Azure so customization 503 error may not work on Windows Azure.

IIS 5.1 + ASP .NET MVC 3 + Image not loaded

I am developping a web application by using the ASP .NET MVC 3 framework.
I am using Windows XP Professional on my computer.
I have decided to execute my web application via my IIS 5.1 local server during the development.
First I have installed IIS 5.1.
Then I have created a virtual directory under the default web site for my web application.
Then I have executed the following command line :
aspnet_regiis -i
Then I have added the following extension mapping to my virtual directory :
Executable : C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
Extension : .*
Option "Check file existence" unchecked.
For information here is my RegisterRoutes method written in my Global.asax.cs file :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Accueil", action = "Accueil", id = UrlParameter.Optional } // Default parameters
);
}
When I launch my web application via Visual Studio 2010 in debug mode then I can load one my view with success.
But I noticed that an image was not loaded.
Here is the img tag containing the image :
<img src="../../../Content/images/Valider_064.png" alt="Valider" />
Here is a piece of my web application folder tree :
ActivitesHtml5 [FOLDER] : Root of web application
Content [FOLDER]
images [FOLDER]
Valider_064.png [FILE]
Controller [FOLDER]
ConnexionController.cs [FILE] : Contains the action method to generate my view.
Views [FOLDER]
Connexion [FOLDER]
Connexion [FOLDER]
Connexion.cshtml [FILE] : Razor file of my view.
Does someone know why my image is not correctly loaded ?
How about using url helpers instead of hardcoding your urls:
<img src="#Url.Content("~/Content/images/Valider_064.png")" alt="Valider" />
Also I would totally recommend you to stay away from IIS 5.1 especially if your target deployment server for the application will be IIS 7.0+. Cassini or IIS Express are much better alternatives and are directly integrated into Visual Studio.

Deploying Asp.Net MVC 2 /C# 4.0 application on IIS 6

I got a problem migrating from VS.Net 2008 / MVC 1 to VS.NET 2010 (+C# 4.0) / MVC 2
The web.config has been updated, the site runs well in Cassini, but my problem now is deploying on IIS 6.
I updated the web site to run using ASP.Net 4,
but whatever URL I try, I always have a 404 error. It's as if the routing was not taken into account (yes, the wildcard mapping has been done).
I do not understand this mess and could not google anything interesting...
Thanks for your suggestions !
Ok I got y answer (thanks to a colleague)
When migrating from ASP.Net 2.0 to ASP.Net4.0,
if you meet the same problem,
then check in Web Service Extension if ASP.Net v4 is Allowed.
In my case, after installing the .Net framework 4, it was prohibited.
Will & Mark : thanks for your help, hope it will helps others.
I think I know what's happening: on IIS6, as well as the wildcard mapping you will need a default document (Default.aspx) that routes folder requests to the MVC handler.
There was one included with the MVC1 project templates, but it has been removed in MVC2.
Default.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNameSpace._Default" %>
<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>
and Default.aspx.cs:
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
namespace YourNameSpace
{
public partial class _Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
// Change the current path so that the Routing handler can correctly interpret
// the request, then restore the original path so that the OutputCache module
// can correctly process the response (if caching is enabled).
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
}
}
When you say "It's as if the routing was not taken into account", I suspect that it actually isn't, and this is your problem.
This finally fixed it for me:
I commented earlier, and a wee bit prematurely. My comment to Mark B's post was getting my initial Index view to show up, but then I kept getting the 404 errors whenever I navigated to any other view.
I was also distracted by the green check mark approved solution in this particular forum, but I could not even see the web server extensions folder in IIS 6 on my desktop; therefore, I had no control from that stand point of enabling aspnet 4.0, though I made sure it was installed by performing running the following command line:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -i
Now for the actual piece that finally allowed me to navigate to the other views besides just my Home/Index:
In the Global.asax.cs file of your VS 2010 Solution, you will see code as follows in the RegisterRoutes method:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
I simply added ".aspx" after the {action} section of the tag as follows:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}.aspx/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
And ahla wahla Peanut Butter and Jelly sandwiches. :0)
If you want to do it in C#, just add the System.DirectoryServices reference and this piece should do the job nicely.
DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/W3SVC");
w3svc.Invoke("EnableWebServiceExtension", "ASP.NET v4.0.30319");
w3svc.CommitChanges();
HTH

Resources