MVC IIS production configuration issue (404) - model-view-controller

In my MVC application I have the following mapping:
routes.MapRoute("testRoute", "services/service.js", new {controller = "Home", action = "DoWrokTest"});
I want to return a custom javascript from that call. The problem is that on my localmachine from VS debug it works fine ... but on server I get : 404 - File or directory not found.
Do you know which can be the cause? Do I have to configure IIS in a special way to handle all requests through mvc?

yes you have to do some special configuration if your iis 7.0 runs in classic mode see
http://www.asp.net/mvc/tutorials/using-asp-net-mvc-with-different-versions-of-iis-cs

Related

Redirection from Spring Boot Application of External Website

I am building a Spring Boot Application with SSL enabled.
Now when I am redirecting to some external website with leading http:// explicitly.
for example http://www.example.com. But browser is redirecting it to https://www.example.com
automatically.
As I am not sure the target site is http or https. I want to redirect to the target as it is in my database.
Is there any one could help regarding this issue?
I have tried by returning redirect:http://www.example.com and ModelAndView approach. It did not work.
Note: My action can return html view or redirect to external site.
Try This :
#RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
httpServletResponse.setHeader("Location", projectUrl);
httpServletResponse.setStatus(302);
}
I tried by different ways from the Application. But it never worked.
DevOps have added Load Balancer in the middle and something messed up while setting the Load Balancer rules. They have modified at their end. Now it's working fine.

Any reason this WebAPI call works in dev but will not work on Win2012? "Unable to locate a controller for ..." error

I am stuck trying to find the reason this happens. I have a WebAPI service in my module. A specific call to a public entry point (the default path) works fine on my dev machine (Win7, IIS 7.5) but doesn't on the production server (Win2012, IIS8). The DNN installations are clones. Here is the call:
/DesktopModules/DNNEurope/LocalizationEditor/API?tabid=1&moduleid=4
The Win2012 installation replies with "Unable to locate a controller for ..." and then naming the path and namespace this controller is in. Note the routing should work just fine as it works fine in dev.
There is one quirk to note, here. I'm supplying the tabid and moduleid through the querystring, rather than through headers as is the practice when you're doing json exchanges. That is because this call is supposed to be consumed elsewhere. Again, keep in mind this works fine locally.
The route definition is:
mapRouteManager.MapHttpRoute("DNNEurope/LocalizationEditor", "Default", "", New With {.Controller = "Localization", .Action = "ListObjects"}, New String() {"DNNEurope.Modules.LocalizationEditor.Services"})
and the method:
<HttpGet()>
<AllowAnonymous()>
Public Function ListObjects() As HttpResponseMessage
Any ideas?
Kiran's remark put me on the right track. In the project there was a reference to the Mvc library that was not on the server. Strangely enough for the asp.net application this is not a problem but for WebAPI this is. Even though any of the methods in the Mvc library were no longer used as I switched to WebAPI at one point during the project. So locally this Mvc library was still found, but not in production.

ASP.NET FileContentResult always 404 in production

I have an ASP.NET MVC 3 web app that's behaving strangely. There's an action that allows me to download a test file:
[HttpGet]
public ActionResult Download()
{
var cd = new System.Net.Mime.ContentDisposition
{
FileName = "test_file.txt",
Inline = false,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(System.Text.Encoding.Unicode.GetBytes("HELLO THERE"), "text/plain");
}
In debug mode it works no problem, I get a file download as expected ("test_file.txt", with contents "HELLO THERE").
When published, and deployed with IIS 6, a 404 error is always returned. Anyone know why the difference and how to fix it?
Turns out the issue was a combination of routing and IIS configuration. I had some parameters for the action, one of which contained a file extension. I had set up a route so that the parameters were in the format
../Download/[text].txt
instead of
../Download?[text].txt
IIS was reading this as trying to access a file on the file system. I removed the custom route and all was resolved.

ASP.NET MVC2 Empty Project Not Loading

My environment consists of Visual Studio 2010 and Windows 7 a few months ago I developed an MVC2 application with no problems however after trying to create a new project recently I received the error below.
I did find the link http://support.microsoft.com/kb/894670 but this is not relevant because I am not using IIS for testing, just F5 to get this working :)
Any ideas or help would be appreciated.
Server Error in '/' Application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927
The Empty MVC 2 template application does not define any controllers or views. When you create a new Empty MVC 2 application and immediately run it, you will see the error message you posted.
If you check the Global.asax file, you'll see that the project template automatically registers a default route specifying a default controller named "Home" and a default action named "Index".
To get this to run, right-click on the Controllers folder, then choose Add->Controller... Name the controller "HomeController". You can leave the check box to "Add action methods for Create, Update, Delete..." unchecked.
In the HomeController.cs file, right click in the Index() method and choose Add View...
Leave the View name as "Index", uncheck "Select master page", and then click Add.
In the Index view, you can enter some HTML and run the project; you should now see the page rendered by Index.aspx.
One thing I am not sure of is why your error message lists the .NET Framework version as 2.0. If you still have problems, check the target framework on your project properties.
Make sure that the routes are set properly and that you have default values for a controller and action. For example if you have the following route:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
Make sure that you have a HomeController with an Index action.

Introducing MVC into ASP.Net - 404 error

I have an existing ASP.Net Application, into which I am attempting to introduce MVC2.
Hopefully I can remember the steps, but what I did was the following:
Created a dummy MVC2 project.
Compared and merged .csproj, resulting in the Add Item commands showing MVC2 items.
Compared and merged the web.config
Compared and merged the global.asax.cs
Added Models, Views and Controllers directories
Added HostController with Index action and Index.aspx (no logic)
Amended route to make /Host/Index the default
So now, when I access the application via the root address http://localhost/MyApp it all works.
But, when I access http://localhost/MyApp/Host/Index I get a 404 error. I get the same result for any of the Controller/Actions I created. The only way I can get them to appear is to use the defaults in the routing configuration. I installed Phill Haack's route debugger and it's doing nothing. Obviously there's some problem with my routing, but I can't figure it out.
Any ideas what I've missed?
Bah... turns out that this is to do with IIS 5.1 and MVC routing.
I resolved it by using the following Routes in my application (note the .aspx extensions).
routes.MapRoute("Root", "", new { controller = "Host", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}.aspx", new { controller = "Host", action = "Index" });
Means I can't have clean routes, but at least it works.

Resources