I am trying to integrate an old ReportViewer Webform into my current MVC3 project. I would like it to be available at http://<server>/Reports/ViewReport.aspx. At first I created a folder in the root of my project titled Reports, dumped the page in there, and it worked just fine.
However, I now have an Area also called Reports, and I had to get rid of the folder in order for the default routing to work correctly.
How can I configure my routing so that the Webform URL appears to be coming from Reports even if it's physically elsewhere in my project?
The easiest way to do this is to use IIS URL Rewrite module. No changes to your application's code or routing. Just place your webpage somewhere in some non-MVC related folder that is also accessible.
http://www.iis.net/download/urlrewrite
But otherwise you could try putting your file directly in area folder as the RouteCollection.RouteExistingFiles is by default false which means that your file should be processed by the usual Asp.net web forms pipeline.
The most important thing is though that you don't put your file inside a folder with configured System.Web.HttpNotFoundHandler handler. By default Views folders have these configured so files within sub-folder tree are inaccessible from request level. Application of course can access them (that's how MVC works anyway).
Related
We have a custom CMS site in which the admin can make a change to the _Layout.cshtml (since they are making lots of changes). The site was hosted in Azure Web Sites, but now we are moving it to Cloud Services.
Now, the admin panel is reading and showing the contents of _Layout.cshtml (actually, all of the files in the ~/Views/Shared folder can be edited), but when the application is trying to write to a file, it throws this error: Access to the path 'F:sitesrootViewsoasShared_Layout.cshtml' is denied.
We are working on a new way to edit the layout files, but before we get there, we need a quick fix!
I am using this method to write to the file: System.IO.File.WriteAllText(path, fileContents);
Locally, in the windows azure emulator, this is working correctly, but not when it's hosted on Azure.
Thanks!
First of all, I have to say there will be some problems even though you can update your _Layout.cshtml file.
If you have more than one instances of your web role, once admin changed the page, it will only update the file one that instance, but others will NOT be changed by default. You have to somehow sync them.
If your instance had been moved to another virtual machine, for some reasons such as hardware failure or virtual machine resource reallocation, all changes your admin made will be lost.
So I strongly recommend to amend your implementation. How about save the change part into BLOB, table or database, then when the page was rendered you retrieve the content from DB. I think this would be better than just modify the page itself.
HTH.
I've an existing MVC3 project that implements a certain functionality, this project has it's own views, and a separate Database.
now I'm required to use the same functionality inside one of my orchard project,so I thought that I can host this solution in somewhere and view it inside an iframe or something.
Am I thinking right?,
is this the correct step to take in order to achieve this requirement inside Orchard?
to make it more clear, all I need to do is to view this solution and interact with it's controls and views from a hosting page inside orchard, and the subsequent requests should be handled by my solution in order to hit it's own data store and get back with the requested data in order to be displayed to the user.
any help would be appreciated.
Update:
thanks for Bertrand Le Roy for his answer, I can now view my solution inside my
orchard website.
I came in to one more HUGE problem, which is that my application can no longer connect to my external database.
I've a DB that is hosted in some where else, and I'm using EntityFramework to deal with it.
the problem is that if I put the connection string inside my module web.config, or main orchard web.config, I run into several types of errors like:
"System.Reflection.TargetException: Object does not match target type."
or
"System.Data.MetadataException: Unable to load the specified metadata resource."
My question is: How could I pass my connectionstring correctly to my solution, assuming that I'm using Entity framework as my ORM.
Many thanks.
You will need to put it into a module.
You will have to move route definitions to a Routes.cs file (look at any existing such file for examples).
You will also need, in order to access your data store, to opt out of the ambient Orchard transaction around the data access code (using (var scope = new TransactionScope(TransactionScopeOption.Suppress))).
If you are using dependency injection, you may have some work to move that to the Autofac-based way of doing things in Orchard.
If you want your work to appear seamlessly in the Orchard admin, you may want to decorate your admin controllers with the Admin attribute. If you want your front-end to use the current theme, you'll have to add Themed attributes and maybe refactor your views so that they only emit HTML for the content zone instead of for the whole page.
Add a manifest (module.txt) to your module folder and you should be good to go.
Should the FactoredProfileProvider.cs be placed in App_Code only? What is the standard way to do it? Can I put it under an Area that handles all accounts?
Should the FactoredProfileProvider.cs be placed in App_Code only?
Absolutely not. The App_Code folder should never be used with the web applications model which is what ASP.NET MVC uses. This folder is used only with websites. See web application vs website. So in ASP.NET MVC you could place this file wherever you want, like for example you could create yourself a subfolder called ProfileProviders and put it inside.
Today I found a weird thing in my MVC 3 app. It's quite large so I decided to use Areas. Evrything is setted proper, but for the request on SomeArea/SomeController/SomeAction I recieve 404.
On fresh MVC3 app this works as expected.
I tried to debug the app and I beieve the problem Is in Global.asax in which Method Application_Start calls AreaRegistration.RegisterAllAreas and this method should fire RegisterArea in TestAreaRegistration class. In RegisterArea is the routing rule for this area.
I fresh app, when I set a brekpoint inside RegisterArea it is reached when server strats, but in previous app, breakpoint on this place in never reached.
I havent found any differences between these two app. Normally I would take the content from previous app and put it into new, but the app is under TFS.
A few things worth checking are:
Areas are being registered. There should be a MyAreaRegistration.cs file in the area sub folder plus the list in Global.asax.cs
Does the folder containing the views match the controller name?
Is your link/ActionLink pointing to the correct place?
Does your controller have the correct namespace?
I'm having issues serving out static (image) files from an Azure + MVC 3 project when running in the dev web server. I have forms authentication running on the site, and any requests for images are met with a login redirect.
I have been able to make access possible by making my images folder an application (via iis) and explicitly setting my windows user to have access to the images folder, though this only works for a debugging session, and clearly isn't a real solution.
There are a couple of problems it isn't:
Static file requests being picked up by mapped routes
Folder permissions not allowing access to the NETWORK SERVICE account
Rules in web.config requiring authorization for the folder
Currently the images reside in ~/Images/... though I have also had them in ~/Content/... which is where the main css resides. Said css always serves out without any issues.
Notably the images are not served even if you do log in.
I realise that it may be better to store these images in a blob, particularly in the development phase, and for source control, it seems easier to carry these few static resources in a project folder.
EDIT - Question was incorrect. Actually just an issue with some files being encrypted on my hd and others not, causing odd results.
It turns out windows was encrypting all of the files in these directories (not standard behaviour for my configuration, but was happening here for one reason or another). I had a couple of images that weren't encrypted (including the styles.css) but most of the images were. That meant that images wouldn't serve without my credentials against them...
So nothing to do with mvc / azure / cassini!
My guess is that this is some config issue and is not related to Azure itself.
It is probably worth trying similar questions/answers like:
My ASP.NET MVC2 application with Forms Authentication is blocking access even to Images, Styles and Scripts
Also, if you create a new project then do you see the same effect?
If no, then compare the web.config type settings one by one - the difference will be there.
If yes, then it seems like the problem is somehow at the web server/machine level (maybe something to do with anon or windows authentication in web.config and/or app.config)