MS MVC Preview 2 and .NET 3.5 sp1 - asp.net-mvc

I have a site built with MVC Preview 2 and have not got around to upgrading to latest release, mainly because of the number of changes required and I have not had time. Anyway, last night my host installed .NET 3.5 sp1 and it killed my site. It is an identified problem (thats what you get for using pre betas) on this site http://haacked.com/archive/2008/05/12/sp1-beta-and-its-effect-on-mvc.aspx and it says to go to this site for a work around http://www.asp.net/downloads/3.5-SP1/Readme/default.aspx.
Unfortunately the work around seems to have been taken down. Can anyone shed some light of what it did say and what the work arounds are.

Maybe this instructions are useful, they are to migrate the site on mvc preview 2 to mvc preview 3. As preview 3 sites are not affected by the beta sp1, I hope it helps:
Upgrading an Existing Preview2 Application to Preview 3
The information in this section describes the changes you must make to modify an ASP.NET MVC application that was created with the Preview 2 release so that it works with the Preview 3 release.
Code Changes
Update the references to the following assemblies to point to the new Preview 3 versions of the assemblies:
System.Web.Abstractions
System.Web.Routing
System.Web.Mvc
By default, these assemblies are located in the following folder:
%ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC Preview 3
For all existing action methods, change the return type from void to ActionResult.
Anywhere you call RenderView, change it to a call to return View. You can search for RenderView( and replace it with return View(.
Anywhere you call RedirectToAction, prepend the call with the return keyword. Search for RedirectToAction( and replace it with return RedirectToAction(.
If you use a strongly typed page, replace <%= ViewData.PropertyName %> with <%= ViewData.Model.PropertyName %>. Rather than replacing the ViewData object with your strongly typed object, the MVC framework now sets the Model property to the instance that you provide.
In the Global.asax file, remove the route definition for Default.aspx. In the default Preview 2 template, the route looked like the following example:
routes.Add(new Route("Default.aspx", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }),
});
In the Global.asax file, find the following default MVC route:
routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { action = "Index", id = "" }),
});
Replace it with the following route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
Add the following line at the very beginning of the RegisterRoutes method:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Edit the Default.aspx file and add the following line:
<% Response.Redirect("~/Home") %>
This redirect is not necessary for IIS 7. This is a workaround for an issue with how the Web server that is built into Visual Studio (the ASP.NET Development Server) works with routing.
Configuration Changes
In the Web.config file, you must change the type attribute of the httpHandler entry in the section for UrlRoutingHandler to System.Web.HttpForbiddenHandler.
To do this, search for the following string in the file:
path="UrlRouting.axd" type="System.Web.Routing.UrlRoutingHandler, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
Replace it with the following string:
path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Because the version numbers of the System.Web.Abstractions and System.Web.Routing assemblies have been changed to 0.0.0.0, you must update version information in the Web.config file. In the Web.config file, search for the following string:
System.Web.Routing, Version=3.5.0.0
Replace it with the following string:
System.Web.Routing, Version=0.0.0.0
Search for the following string:
System.Web.Abstractions, Version=3.5.0.0
Replace it with the following string:
System.Web.Abstractions, Version=0.0.0.0

Related

MVC Site not working when published to web hosting provider

I am trying to publish an MVC site. The website/application are both setup for .NET Framework 4. When the site is published, the MVC page gives the following error:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Also if I try to bring up a test aspx file, I get this error:
"The resource cannot be found."
The first test I perform is to delete the web.config. At this point, I attempt to bring up an MVC page again and same error is displayed:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
However, if I try to bring up a test aspx page now, I actually get the page:
1 + 2 = 3
The test aspx page just contains this:
<html>
<body>
1 + 2 = <%=(1+2).ToString() %>
</body>
</html>
Any help of what to check next would be appreciated. Saw similar threads where it mentions of adding:
<customErrors mode="Off" />
and
<asp scriptErrorSentToBrowser="true"/>
But that still gives me the same error when bringing up a MVC page. Any help on how to proceed next to fix this MVC site would be appreciated. Thanks.
Update #1
I did a search for the keyword "routes.MapRoute" in the entire project and found it only once in the RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
The page I am testing is:
http://.../Home/Index
This is the page that returns:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I found the problem! The problem was that the website hosting provider had the website setup for IIS 6.0. In that case there are two options:
Update hosting site to support IIS 7.0. This was my solution and solved the problem
Set the MapRoute to run a "fake" aspx page: (only do this if you cant update hosting to IIS 7.0):
// IIS 6.0
routes.MapRoute(
name: "Default",
url: "typehereanything.aspx/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Using this second method is not recommended since now you have to plug in "typehereanything.aspx" into every URL: http://.../typehereanything.aspx/Home/Index
Any of those two options solved the issue.

ASP.NET MVC 3: RouteExistingFiles = true seems to have no effect

I'm trying to understand how RouteExistingFiles works.
So I've created a new MVC 3 internet project (MVC 4 behaves the same way) and put a HTMLPage.html file to the Content folder of my project.
Now I went to the Global.Asax file and edited the RegisterRoutes function so it looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.RouteExistingFiles = true; //Look for routes before looking if a static file exists
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
}
Now it should give me an error when I'm requesting a localhost:XXXX/Content/HTMLPage.html since there's no "Content" controller and the request definitely hits the default pattern. But instead I'm seeing my HTMLPage.
What am I doing wrong here?
Update:
I think I'll have to give up.
Even if I'm adding a route like this one:
routes.MapRoute("", "Content/{*anything}", new {controller = "Home", action = "Index"});
it still shows me the content of the HTMLPage.
When I request a url like ~/Content/HTMLPage I'm getting the Index page as expected, but when I add a file extenstion like .html or .txt the content is shown (or a 404 error if the file does not exist).
If anyone can check this in VS2012 please let me know what result you're getting.
Thank you.
To enabling routing for static files you must perform following steps.
In RouteConfig.cs enable routing for existing files
routes.RouteExistingFiles = true;
Add a route for your path ( Make sure specialized path are above generalized paths)
routes.MapRoute(
name: "staticFileRoute",
url: "Public/{file}/",
defaults: new { controller = "Home", action = "SomeAction" }
);
Next configure your application, so that request for static files are handeled by "TransferRequestHandler".In Webconfig under system.webServer>handlers add following entry.
<add name="MyCustomUrlHandler2" path="Public/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
The value of 'path' can be more generic or specific depending on your requirement. But i prefer it to be always very specific as per one's need. Keeping it very generic will block serving of other site specific resources such as .js or css files. For example if above is set as path="*", then request for even the css (inside the content folder) which is responsible for how your page would look will also end up in your Controller's action. Something that you will not like.
Visual Studio 2012 uses IIS Express. You need to tell IIS not to intercept requests for disk files before they are passed to the MVC routing system. You need set preCondition attribute to the empty string in config file:
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule"
preCondition="" />
In Win7/8 you can find config file on this path: %userprofile%\Documents\IISExpress\config\applicationhost.config
The RouteExistingFiles doesn't keep files from being viewed if there is no route for them, it just checks the routes before checking if the file exists. If there is no matching route, it will continue to check if there is a matching file.

MVC route to capture file name as a parameter

I am attempting to produce a simple WebDAV server using MVC, and I have finally reached the stage where I need to serve up a requested file to the user.
I have a route set up that deals with traversing the directory structure "webdav/{*path}" which works fine, right up until the point where that path ends in a file name. At this point, it appears that IIS decides that it is a static file, and attempts to serve that file from the disk. As it isn't in the location specified in the URL, it returns a 404 error.
I don't have any freedom to change the url, I basically need it to be in the form, otherwise Windows Explorer can't work with it as a mapped drive:
GET /webdav/Test/Test2.txt
I've set the route to greedily match, as the directory structure can have as many levels. I've also set routes.RouteExistingFiles = true;
This is using IIS Express 8.0 on my development machine.
I've gone as far as setting up a blank MVC project just to test this, and this is the RegisterRoutes method:
routes.RouteExistingFiles = true;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "WebDAVGet",
url: "webdav/{*path}",
defaults: new { controller = "WebDAV", action = "Get", path = "" });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
So, going to /webdav/Test/Test2 hits the breakpoint in my controller, but going to /webdav/Test/Test2.txt gives me a 404.
Any suggestions?
I needed to add
<modules runAllManagedModulesForAllRequests="true">
to the web config.
Ah, I've been struggling with this for a few days now, I knew posting here would shift the blockage!
Another option is to add this to the <system.webserver> node in web.config:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
I can vouch that this works on IIS 7.5.
For the record, I found this solution here.

Why can't I get the MvcHttpHandler to handle my .mvc requests?

I have a project using Asp.Net 3.5 and MVC 1.
Everything runs perfectly on my local IIS, but not after I deployed it to the hosted server.
The web server is IIS7 with integrated pipeline activated (according to the hosting company).
When I go to the root of the web site, www.site.com, the default.aspx makes a redirect to a controller like so:
public void Page_Load(object sender, System.EventArgs e)
{
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath + "Controller.mvc/Action", false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
This works and the correct view is shown. However, when I type the same address in the browser, www.site.com/Controller.mvc/Action I get a 404.0 error. So it seems the MvccHttpHandler is not invoked correctly(?).
The web.config is set up with runAllManagedModulesForAllRequests="true", and a MvcHttpHandler is configured to handle .mvc extensions.
What am I doing wrong, any ideas?
Here's a good article which covers different deployment scenarios. There are no particular steps required when deploying to IIS 7 in integrated mode. You don't need a default.aspx file and association of MvcHttpHandler with the .mvc extension in your web.config. Here's how your routes might look like if you want to handle both extensionless routes in IIS 7.0 and the .mvc extension in IIS 6.0.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// This is for IIS 6.0
routes.MapRoute(
"DefaultWithExtension",
"{controller}.mvc/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// The default extensionless route working with IIS 7.0 and higher
routes.MapRoute(
"Default",
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The .mvc extension is needed only for IIS 6.0:
<httpHandlers>
<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
Turned out my hosting company did not run my application in integrated mode, even though they told me. Solved my problems, but I also got a few helpful tips from Darin.

Asp.Net MVC Url.RouteUrl Problem on Windows 2003 vs. Visual Studio 2008

I'm seeing a difference in the output from Url.RouteUrl between my development machine and my deployment server. I'm running Visual Studio 2008 and my deployment box is Windows 2003 Server. I have configured the Global.asax.cs to run with the .aspx extension in my routing tables. However, when I use the "Search-Basic" named route, there is no output from Url.RouteUrl("Search-Basic", new {category = "Test", searchExpression = "search this"})
View Code:
<%= Url.RouteUrl("Search-Basic", new {category = "test", searchExpression="search this"}) %>
Global.asax.cs Code:
// routes for IIS 6 and version below
routes.MapRoute(
"Search-Basic",
"Search.aspx/Basic/{category}",
new { controller = "Search", action = "Basic", category = "All" }
);
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
On my development box, I get the expected output: /Search.aspx/Basic/Test?searchExpression=search%20this
However, on my deployment server I get no output at all. One difference perhaps is that I'm running the application in a virtual directory on my deployment server; something like: http://testmachine.com/sm/testappname/ where "/sm" is a virtual directory and "/testappname" is a virtual directory holding my application.
Any ideas?
Thank you kindly.
Are you running the same version of ASP.NET MVC because there is a bug in the RC1 (non-refresh) that causes this behavious when you have a route where e.g. the controller is not specified in the route:
The other regression is that in some
cases, the RouteUrl (and thus
RouteLink) methods return an empty
string when you specify a route name,
but the route has default parameters
which are not parameters in the URL.
For example, if you have the following
route:
routes.MapRoute("route-name", "foo/bar", new {controller="Home", action="index"});
Notice that controller has default
value, but is not part of the URL. If
you then specify:
<%= Url.RouteUrl("route-name") %>
You might expect that it would use
that route to render the URL, but it
doesn’t. This bug was introduced when
we refactored all our url generating
helpers to call into a common method.
It turns out, however, that our
RouteUrl methods (aka non-MVC
specific) should have subtly different
behavior than the MVC specific methods
(such as Action). We added a flag to
the common method so that this
difference is taken into
consideration. This was a fix that did
not have a large surface area.
See http://haacked.com/archive/2009/01/30/aspnetmvc-refresh.aspx

Resources