HI am new to ASP.NET MVC and I am running into some issues trying to deploy a very simple site! I took the MVC Storefront (Kona), made some basic changes and now I would like to deploy it to a webserver! For testing, I just turned on IIS7 on my windows 7 desktop! I change the web projects settings to use local IIS and run it!
The first issue I get is the "Request is not available in this context"... To fix this I had to remove the HttpContext.Current.GetSiteUrl() in the global.asx.cs file! If I now run the app it works but I have no css? If I switch back to VS development server everything works great?
I can also swithc from integrated mode on IIS to classic which makes the css work but then I have no routing?
On IIS 7, HttpContext.Current is null in Application_Start because it isn't triggered by the first request anymore.
You can work around that issue by moving the code from Application_Start to Application_BeginRequest and add a flag to indicate if the application is already initialized (member of the Global class). When false, execute the code that uses HttpContext.Current and set the flag to true so subsequent requests don't execute that piece of code.
Doing what is said above fixed the css for me but adding this to
http://blogs.msdn.com/mikeormond/archive/2008/11/06/and-getting-asp-net-routing-up-and-running-in-web-applications-and-on-iis7.aspx
Fixed the routing for me.
Good luck took me long enough!
Related
I'm trying to enable Windows authentication (setting windows mode on authentication) on a huge legacy ASPNET MVC 3 Application, but it isn't working and I can't find why; the Request.IsAuthenticated is always false. The app is very huge and has a lot of personalization with its own authentication and authorization system, but it uses the standard mechanisms of ASPNETMVC to override them (OnAuthorize). I've tried with empty controllers without "personalization" but it doesn't work neither.
I don't know how to start to write here all configuration so, I'm expecting for a genius who could point me to what is wrong...
I've tried too on a sampe new ASPNETMVC3 (from VS2010 templates) and it works fine; I would try to set every thing of my app on this one slowly to try to reproduce if I didn't found any solution before.
--- UPDATE ---
I've copied the web.config and global.asax of template project and it's not working yet. I've added the event WindowsAuthentication_OnAuthenticate on both projects and only enters on the demo project. I can't undersand how, where or why the ASPNET flow is broken.
I don't know anyone can help but I'd appreciate any. I am developing an app in mvc (c#), now I had various routes working on my local development machine when the app was stand alone however now I've tried adding the project to the test intranet at work and none of the routes are working.
So where Localhost/Admin/Create worked fine locally where admin is the controller and Create is the action, when I try to get to testintranet.mywork.com/intranetsection/myproject/admin/create I'm getting a file not found error. I'm not sure what I need to change to get it to pick up the routing again rather than look for the literal path. The default.aspx page works fine and gets called but apart from that nothing. Is routing only viable when in a standalone project?
Cheers for any help.
It looks like you're either running on IIS 6 or IIS 7 classic mode. If you can, I'd recommend updgrading to IIS 7 integrated mode. If not, I have a walkthrough for getting up and running on IIS 6.
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
You don't say what version of IIS you have deployed to, but you may be running into the issues described here:
http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
I believe that most people chose to resolve this using a wildcard mapping for the aspnet_isapi.dll.
I just got a new development box and am having issues getting my MVC project up and running. My old box had Server 2003 and IIS6. I was able to get my MVC apps working on this box after setting up the wild card mapping as mentioned here. My new box is running Vista Business and IIS7. When I copied my app over and tried to run it, I get an 'http 404 The resource cannot be found.' error. However, if I create a new MVC app and run that, everything works fine. I also copied the Nerd Dinner app over from my old box and that works fine as well.
I've verified that the app is running in Integrated Mode and have compared the web.config files of the working and non-working apps but see nothing that is different other than application specific appsettings. I have tried to run the app in Classic Mode with the wild card mapping set, but that does not work either. I have also tried running the app using Cassini, but got the same results.
I have posted the answer on my blog, check it out at
http://nkitdugar.blogspot.com/2011/02/special-care-while-migrating-mvc.html
I had a MVC based application that was earlier hosted on IIS 6. Now IIS 6 doesn't support extensionless URL routes by default, so we need to add some extension to the controller name in the default route defined like {ControllerName}.aspx{Action method}{Id} in IIS6. Also we if we wanted to go for some other extensions like .mvc etc. then we needed to map it using techniques like wildcard mappngs etc.
Now when we have migrated to IIS7, then extensionless URLs are supported which means URLs can be there which don't have any corresponding physical location.
So when you are migrating your MVC application to IIS7 then make sure the default route define in Globla.asax don't have any extension defined with controller like {controller}.aspx\{action method}\{Id} and change it to \clean URL route {Controller}\{Action Method}\{ID(optional)}.
Second thing you should keep in mind that the pipeline mode of AppPool of the website should be set to Integrated from classic.
That's all now your website is ready to be hosted on IIS7.
OK, I figured out the problem. The App in question is a port of a Web Forms app over to MVC as a proof-of-concept project. As such, when the project was first created, we just added a .MVC to the end of the project name to make it {project name}.MVC. This, not surprisingly now that I know what's going on, caused a problem with the default routing definitions. I changed the name to use an underscore instead of a period and everything works now. I'm assuming that it worked fine while running under IIS6 since it was setup using a wild card mapping and therefore there was no .MVC extension to confuse it.
I have a mixed MVC and Web Forms environment that works just fine in VS2008 when I debug. However when I deploy the code to my staging environment I have issues.
Basically I'm using an old school URL Rewrite module for the old Web Forms app, so I have to run the App Pool in Classic Mode for the old URL Rewriter to work. However, when I do that I get 404 errors on my MVC stuff. But if I switch them to Integrated Mode my URL Rewriter doesn't work.
The real rub is that, like I said, both the old URL Rewrite module and the MVC stuff work just fine on the test web server you get when you debug in VS2008.
Is there a way to export to or mock those settings in IIS 7?
Another thing I guess I wouldn't mind would be to set up my Web Application on my local IIS so I can at least develop against the same settings and figure out what's breaking that way. But I'm not sure where I would begin there.
Steve Sandersons blog has a good description regarding setting IIS for mvc. Your problem might potentially have to do with handler mapping. Basically you need to map ".*" requests to "aspnet_isapi.dll" but see the blog for an in depth description.
EDIT: wrt the blog, I was referring to his option 1. He also has a few other suggestions.
Any idea on how to get my asp.net mvc website to work on a webhost that's running asp.net 3.5 but maybe not IIS 7? (I think they might be on IIS 6)
I am on Crystal Tech and my home page shows up just fine but all other requests give me a 404 page not found error.
Note: I already follow these instructions but it's still not working
http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx
Have you tried this?
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
I had the same problem - I tried to fix it, but decided that spending the time screwing around with running on a backlevel server wasn't worth it. In the end it was just easier for me to move to a host that ran Windows Server 2008 and IIS7.
If you do have IIS7, then you may have an option to switch IIS7 between integrated and pipeline mode. Try switching to the other mode in your control panel. That's what worked for me.
I fixed it by adding an .aspx at the end of all my routes in the route table("/{Controller}/{Action}/{id}.aspx").
You can add any extension that asp.net handles(like .mspx, .ashx, ...)
The only way to fix it without adding any extension is to ask your host to do so, or change your host to another with IIS7