ActionLink not formatting an Area's URL correctly - asp.net-mvc

I have an MVC 3 site that runs across three load-balanced servers. On one of the servers this link:
#Html.ActionLink("Admin", "Index", new { area = "Admin", controller = "Home" })
gets rendered correctly.
http://my1.mvcsite.com/Admin/Home
On the other two the URL comes out wrong.
http://my2.mvcsite.com/?area=Admin
None of the servers have MVC 3 installed on them so when I push changes I include the deployable assemblies. I know it's not problems with the routes because in other places I'm using fairly complex routes and these work fine on all three servers. Also manually typing routes into the browser works OK but not for the Areas on the two rogue servers.
The issue seems to be that two of the servers don't know anything about Areas, which seems very odd. Has anyone else encountered a problem like this and if so what did they do to remedy this?
Edit
All three servers are Windows Server 2008 R2 DataCentre and run IIS7

Me and a colleague have fixed this problem by removing this file from the Temporary ASP.NET Files from the two rogue servers.
MVC-AreaRegistrationTypeCache.xml
which was found here:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\06304885\908d56a6\UserCache
On the servers where the Areas were not mapped nor found the XML was as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!--This file is automatically generated. Please do not modify the contents of this file.-->
<typeCache mvcVersionId="3cff62e5-ef21-4e58-897f-d0f1eafd3beb" lastModified="10/09/2013 15:10:21"/>
Deleting this file, and re-starting the App Pool, causes it to be re-created and then the Areas work.
The file is now:
<?xml version="1.0" encoding="utf-8"?>
<!--This file is automatically generated. Please do not modify the contents of this file.-->
<typeCache lastModified="04/10/2013 15:45:02" mvcVersionId="3cff62e5-ef21-4e58-897f-d0f1eafd3beb">
<assembly name="MyMVCSite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<module versionId="a3ce0d47-e370-4176-a07b-76aec3a3c25c">
<type>MyMVCSite.Areas.Admin.AdminAreaRegistration</type>
</module>
This feels somewhat wrong in that I'm not certain as to why this occurred; but after two days of banging my head against a brick-wall it'll do.
This article seems to suggest that what I've found is a bug with MVC. I don't know if the issue is with MVC 3 only.
EDIT
Just found this link that suggests there might be a problem with MVC 4

Related

Relative paths in CSS not valid when using MVC w/Bundles

I've been developing a MVC5 web application for several months. I've published to each of 3 servers used for development, testing and the intended public server. Everything has been tested by a team of a dozen beta testers and a decision was made to go live with the web app this weekend.
Prior to publishing the web app to the live (public) host I modified the web.config to disable debug mode for the public site. After publishing, all kinds of problems cropped up related to missing CSS and JS resources.
After reading a lot of articles regarding Bundles and 404 errors, I found one that hinted to add the following to Web.config:
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
This resolved the 404 issues for the StyleBundle and ScriptBundle configurations, but now I have 404 errors for images that previously worked fine. I'm not sure of the best way to resolve these. I don't want to relocate the images and I don't want to edit the CSS since these are distribution files (jQueryUI, ThemeRoller, DataTables, etc). I want to leave their distribution folder structure and original source files (CSS and JS) unmodified.
An example of the problem.
DataTables distribution is in my ~/Scripts folder:
/Scripts/DataTables-1.10.2/
/Scripts/DataTables-1.10.2/media/css
/Scripts/DataTables-1.10.2/media/images
/Scripts/DataTables-1.10.2/media/js
Bundles configuration:
bundles.Add(new ScriptBundle("~/bundles/DataTables").Include(
"~/Scripts/DataTables-1.10.2/media/js/jquery.dataTables.js"));
bundles.Add(new StyleBundle("~/bundles/DataTables.css").Include(
"~/Scripts/DataTables-1.10.2/media/css/jquery.dataTables.css"));
jquery.dataTables.css contains references to ../images/someimage.png and with Web.config debug mode enabled this works flawlessly. Now that debug mode has been disabled and Bundles are minifying/combining, I am getting 404 errors:
http://example.com/GenericError.htm?aspxerrorpath=/images/someimage.png"
It seems as though the image URL is now assumed to be relative to /Bundles/ - though I'm not positive.
There must be an additional configuration I'm missing. Can someone point me in the right direction?
EDIT
Raphael's comments on this question and his URL to another similar SO question did not help to resolve this problem. Sean's recommendation of BundleTransformer seems like it might work but I don't find any documentation on how to install this package.
See my answer at:
CSS/JS bundle in single file in mvc when publish with release option
It deals with this exact issue and the options you have to resolve it.

Deploying ASP MVC 5 App with IIS 7.5

I try to deploy ASP MVC 5 app in virtual directory (without creating new iis application)
I use IIS 7.5
I already put
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
in web.config file.
But when i go to app url with IE browser it shows me just directory listing like in screenshot below
Is there a way to deploy MVC 5 in virtual directory and make it work like usual MVC application?
You need to convert the virtual directory to application. Right click on it in the IIS management console and choose Convert To Application.... Also make sure that the associated application is configured to use Integrated Pipeline Mode.
I solved this problem earlier in my production environment by checking the directory pointer in IIS. Apparently when I unzipped the deployed site from one server to the next, the zip utility made an extra level, so IIS was pointing to /MyProject when the files were in /MyProject/MyProject. I had a little better clue though, you have Document Browsing enabled based on that screen shot, make sure not to do that in production. I set the site to log custom errors and got a 403.14 response, from there found a blog on my mistake. You need to setup the environment to find the specific module that's failing, I think something to do with trace routes, idk. I'm a software developer that always gets forced into doing devOps; was googling my own problem and thought I'd throw you a line. Without a specific error message, all I can tell you is IIS is not connecting to .NET; something is not configured correctly. Turn off directory browsing, google how to get good error logs back, and let us know the status code so we can help you: 403.14, 401, 500, 404? Also give us the module that's failing. If it's the last one on the handler list, guess what, IIS isn't connecting to the app, which I suspect is your case.

Hosting an MVC and a webforms site on the same IIS7 instance - web.config inheritance

We have a website that was written in classic ASP, then I started to extend it using web forms. These extensions exist in a subfolder of the main folder. Now we've decided we'd prefer to use MVC3. Also, as we'd like to convert all our site to MVC3 over time, we are hosting the MVC code in the application root. I've found some other questions where people have a similar issue to mine, but no solution. The issue is simply that my web forms app can't seem to be stopped from inheriting the web.config settings from the root folder, and as a result, it won't run, it either complains about missing dlls, or complains about running the wrong version of .NET, or complains I need to remove some settings ( which I try and can never get to work right ). The app in the subfolder is also hosting a webservice that is called by our application, and it also runs HTTP handlers to protect our imaging content, so it's got a bit of stuff in it. Do I need to run my MVC site in a subfolder ? Is there any way to have MVC in the folder above a web forms app ? I'd prefer to set things up so they share session data, but that's looking likely to be impossible at this stage...
So to be clear the folder structure is:
<root>
contains asp site and MVC site.
<subfolder>
contains webforms application
</subfolder>
</root>
and my issue is getting the subfolder to run, preferably in the same session as the MVC app.
There is no reason you can't run regular .aspx files on an MVC site. You are correct though, web.config settings are inherited from the parent (chain), but you just add a new web.config in your directory with relevant settings.
What you will have to do is play with the routes, because by default MVC will route all requests into your controller classes. But if you google around its fairly simple to add an exception to the routing.
If you post some of the specific errors we can probably help further.
Oh and do you mean Classic ASP? i.e. not Classic ASP.NET? Because you'll have fun sharing session data between ASP & ASP.NET.

How do I display a Web Forms page from an MVC 2 application?

The Report Viewer control apparently only works in a Web Forms page (I'm using MVC 2). So, I make one, add my report to it, and try making a link to it from one of the Views in my MVC 2 site. I consistently get the error "The resource cannot be found". I've tried every possible URL I can think of it get it to work. I even dragged and dropped a Hyperlink tool into the page and set it to link to the Web Form in question and got the same results.
The Web Form is in the /Views/MaintenanceReports folder. I've tried URLs such as ~/Views/MaintenanceReports/DriverList.aspx (with and without the *.aspx) and a few others. But, I'm very sure this should be the URL.
I also added this page route to the Global.asax file in hopes that it would do something magical routes.MapPageRoute("DriverListing", "MaintenanceReports/DriverListing", "~/Views/MaintenanceReports/DriverListing.aspx");
I also tried adding, per the suggestion of one of my fellow programmers, an iframe to an MVC View that had the Web Form in question as its source. This also gave me the same error.
I've got the book Pro ASP.NET MVC 2 on hand and it doesn't give me anything that helps. It basically says that there shouldn't be an issue.
The server runs IIS 7 and has the .NET 4 framework installed.
Normally I'd spend more time looking for an answer, but I'm quite pressed for time currently. This is my last day here (internship) and I'd like to get this last thing done before I leave.
Thank you for all your help.
Try using the StopRoutingHandler. I think the issue is you need to tell MVC to ignore those urls.
routes.Add(new Route("MaintenanceReports/{*resource}",
new StopRoutingHandler()));
Update
It looks like the above doesn't work for routing within the Views folder. The simple solution is to move the WebForms out of the Views folder, and the WebForms work out of the box alongside MVC.
You can also add this line into to display a .asxp page
<httpHandlers>
<!-- see below -->
<clear />
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory"/>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
</httpHandlers>

IIS not serving up .dat files

I have a ASP MVC web application that uses a plugin to load images and points for a 3d application.
When debugging with the the Visual Studio development server the images and the points are served up great...
http://i148.photobucket.com/albums/s19/littleniv/Debugging/local.png
Second image: same url but iis.png
When running in IIS 7 though the .Dat point files do not serve and produce a 404.
I've noticed the caching is marked as private in fiddler, but i don't know what this means. Can anyone help?
Cheers,
Stu
It's been a while, but I have seen a similar issue in IIS 6. IIS by default will only serve a file if it is configured to serve it based on the extension and mime type.
Go into the IIS Manager, click on the server, then open up "MIME Types" under the IIS Area. Hit "Add..." in the upper right corner (under actions), and type in your extension (".dat") and a mime type (depends on your data; maybe "application/octet-stream"?).
Once you've done that, you should be able to download the files.
I ran into this issue while trying to serve a blazor wasm application.
First try to browse the application locally on the web server. If you see an error similar to image below,
Network Tab Screenshot
You can make out that the Requested URL shows, Rejected-By-UrlScan added to the actual URL.
So the url scan is rejecting the .dat file request. To fix this url scan has to be configure to serve dat file types.
Open up UrlScan.ini (I found it in C:\Windows\System32\inetsrv\urlscan folder)
Find the DenyExtensions section and comment / remove the line starting with .dat
Now you will be able to load .dat files.
Hope, this answers helps someone.
OK. Apparently the 404.3 50 error is ERROR_NOT_SUPPORTED. Can anyone shed any light?
ALL STOP!!!
I added a static file handler mapping and everything is solved. Many thanks to Chris for helping me run through some trouble shooting. I'll mark you as the answer as you are the only one that helped!! Thanks again!!
Eek. I have multiple accounts on SO... this is going to take some sorting out!
For an Azure web app, the following change to the web.config did the trick, thanks for the Mime type clue:
<system.webServer>
<staticContent>
<remove fileExtension=".dat" />
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>

Resources