ASP.NET RAZOR Urls? Getting 403 - asp.net-mvc

I used WebMatrix to play around and do a very simple site for learning. However, when I upload to an actual Windows server (yes, WebMatrix installed) The MVC style url's dont work.
If you go to http://173.201.29.98:88/
You'll see
But if you go to http://173.201.29.98:88/Default.cshtml
it works.
Anyone know what's wrong? I'll I've done is upload it, didn't use the "Publish" feature.

Lol, after looking more deeply in Stack Overflow I found the answer.
Razor page not working with Rewrite
Pretty Simple.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Related

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>

Images not showing on published ASP.NET MVC Website [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Images in CSS not showing in ASP.NET MVC
I have already asked this but didn't receive an answer that fixed it. I'm asking again because I have tried everything I can think of and am absolutely stuck. My previous question was here: CSS images not showing in ASP.NET MVC
I have an ASP.NET MVC application with images in an ~/image/ directory. When I run it in development, the images show fine. When published, they do not show at all. I don't think it is a reference path issue because I've tried every combination of ../, ./, ~/, etc. I can think of. Neither css references, <img> or <asp:Image> tags work and all have the same problem. I've tried editing windows security on the image and all parent folders to no avail.
When I mouse over the image path in firebug, the image preview box just spins as though the image is found but can't load.
The very strange thing is that when I try to go to the image directly (www.web.com/images/image.png), I am redirected to the default log in page. The default account controller that ASP.NET MVC puts in projects is in my app, but I have not implemented any log in controls yet. So I think it's an issue with authentication. Or perhaps it is an IIS issue?
I appreciate any help you can give. I have been stuck on this for almost a week and may have to abandon images all together I can't get this sorted.
The redirect to a logon page is a usual indicator that your IIS security is set to force authentication before displaying the contents of the specified directory. The images subdirectory is one of those usually permitted to be visible even by unauthenticated users.
Add this to your web.config file under the <configuration> element to allow unfettered access to the contents of that directory:
<location path="images">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
Check the path in firebug. Is it correct?
Are you using the helper to generate the URL? Something like:
<img src='<%= Url.Content("~/images/image.png")' />
I FINALLY figured it out. The image file in question was encrypted. Right click the image file -> properties -> advanced button on general tab -> uncheck "Encrypt contents to secure data" -> OK -> OK.
The tip off finally came when I noticed the file name was green in windows explorer. I see green file names all the time with no problems so I didn't think anything of it. Then I noticed it was the only green file in the entire web app folder. Put 2 and 2 together and it worked instantly. Thanks everyone for your help.
I reread and see that you are using iis instead of casini. Does it work in casino. If it does, then we are dealing with an iis config issue. Sometimes you need to run aspnet_regiis.exe to register asp.net with iis. Seems like a long shot since the other parts of the page are rendering. Worth a try. Here is a link with some additional info http://www.devx.com/vb2themax/Tip/18849.
Just for kicks, put some images under a different folder and try and see if you can hit them without having to authenticate, it would be good if you posted your web.config

Getting 404 error on MVC web-site

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.
However, whenever I try and navigate to a page running in IIS7, I get a 404 error.
I have checked the following things:
There is no corresponding 404 log entry in IIS logs.
Actually, there are 404 entries in the IIS log.
The application pool for the web-site is set to use the Integrated pipeline.
The "customErrors" mode is set to off.
.NET 3.5 SP1 is installed
ASP.NET MVC 2 is installed
I've used MVC Diagnostics to confirm all MVC DLLs are being found.
ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.
EDIT
Ok, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g.
<my_server>/Home/About will generate a 404.
Any ideas will be greatly appreciated!
This is quite often caused by the following missing from the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
Do you have a problem with just 1 page or the whole site is not working?
A) 1 page
You can use RouteDebugger to verify if the route is matched correctly
B) Whole site
I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.
You can use MvcDiagnostics page to check if all dlls are deployed properly.
Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)
Make sure your Web.config tag is configured correctly.
We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.
It was a really obscure setting which had been changed from the default.
IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions
This should be ticked.
This can be set at the IIS level, or the site-level.
Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368
If none of the other solutions here solved your issue, check that you have the
Global.asax
file in your website. This solved the issue for me.
Checkout if KB 2023146 applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index
Apparently this can have many different causes.
For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.
For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)
You'll also get this if your bindings aren't correct. If you don't have www or a subdomain it'll return a 404.
I had this problem when running my MVC4 site with an app pool set to ASP.NET 4.0 and the Classic pipeline, even though the extension handlers were set in my web.config and were showing correctly in IIS. The site worked in Integrated Pipeline so I knew it was a configuration issue, but I couldn't nail it down. I finally found that ASP.NET 4 was disabled for the server in the ISAPI and CGI Restrictions settings. I enabled ASP.NET 4.0 and it worked.
In addition to checking if you're running in integrated pipeline mode, make sure your application pool is set to use .NET! I recently ran into this problem, and when I went in to check the app pool settings, I found that somehow it had been set to "No Managed Code." Whoops!
My Hosting company fixed this for me by doing this (I removed the original password value of course).
<system.webServer>
<security>
<authentication>
<anonymousAuthentication password="<password>" />
</authentication>
</security>
</system.webServer>
Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.
Today however I accidentially created a Virtual Directory in IIS.
It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:
Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

IIS cannot serve pages ending with .config

This is obviously a security issue and probably do not want to change this, but it would be nice to handle the error. Any ideas?
I see that stackoverflow is not immune:
https://stackoverflow.com/questions/tagged/web.config
They seem to have changed the tag to web-config to fix the problem but you still get a very nasty error message when you search for [web.config]
I believe this has been addressed in ASP.NET 4 with the addition of a new web.config setting
<configuration>
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
</system.web>
</configuration>
Phil Haack has more details.
In IIS 7, this can be found under Request Filtering. Other extensions that are filtered by default include:
.asax
.ascx
.master
.cs
.csproj
etc.
It's not a bug BTW, because the request gets filtered before ASP.NET gets a chance to process it. In other words, you could remove the request filter and have IIS process the extension if you want to, but make sure the extension is handled by ASP.NET and not the static file handler.
Edit: Maybe the answer for SO would be to change it so that when tags have a .XXX extension like web.config, they change to web-config or something else that IIS doesn't filter. This probably also would be a good topic on https://meta.stackoverflow.com/

ASP.NET MVC Routing vs. Reserved Filenames in Windows

In our ASP.NET MVC application, we've noticed that we cannot have The Forbidden DOS File Names—COM1 through COM9, LPT1 through LPT9, CON, AUX, PRN, and NUL—anywhere in our routes. They inevitably result in IIS telling us the file cannot be found, even when we set routing not to check for the existence of files first. How can we work around this?
This has been addressed in ASP.NET 4. http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx
You can apply a setting in web.config that relaxes this restriction.
<configuration>
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
<!-- ... your other settings ... -->
</system.web>
</configuration>
Hope that helps.
Since asking the question, I've found that the bug is in ASP.NET proper, not IIS or ASP.NET MVC, meaning that there's no way to work around it. The only solution is to manually forbid URLs matching these names and these names followed by a period and random characters.
For a similar reason, there can't be a web.config tag in StackOverflow.
http://stackoverflow.uservoice.com/pages/1722-general/suggestions/98871-web-config-tag-404-error
for another similar reason you can't have urls with a dot and a slash
Semantic urls with dots in .net

Resources