ASP.NET MVC Displaying Static Help Website - asp.net-mvc

I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?

I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).

Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html

Related

ASP.NET MVC: how to bypass the controller in MVC app?

I have a .NET MVC application. So far, each page is accessed via a controller.
Now I want to direct access some cshtml files such as
http://example.org/file/abc.cshtml.
Though having .cshtml file extension, these are just pure html snippets.
How can I access these files without going through any controller.
Thanks and regards.
I would probably make a controller with an action which accepts a view name, grabs the view from the file system, and returns it as a FileResult with the mimetype text/html. You'd probably want the controller to have a hardcoded whitelist of html-fragment files, to reduce the chances that you're opening up a way for people to browse around your folder structure.
You could also look into configuring IIS to serve .cshtml files from some directories, but I'd be more concerned about accidentally opening up too much using that method.

mvc webpage without using the default templates

I am using MVC 4.I have designed a webpage in Dreamweaver and then tried to convert it as a razor page. I wanted to view it in a browser, without using Visual Studio. I have heard that a Razor page can be edited using a notepad.
Please help, I am comfortable designing pages in Dreamweaver, than in Visual Studio.
If I understand you correctly you have a HTML design (created in whichever tool you prefer) and you wish to create an MVC website out of this. You have experience in ASP.NET Webforms.
Primarily to creating anything I would follow the topics covered in the ASP.NET MVC tutorials of MVC itself. It's not about "default templates" it's about understanding what builds your final output. Layouts, partial renderings etc...
See http://www.asp.net/mvc
PS: Ask yourself: Is MVC the right choice for my solution? (because I get the feeling everyone just wants to use MVC and doesn't think about what it is and why you should or shouldn't use it...)
If you dont't want to use default template then you can include your css files you created in Content folder. In shared folder which is located inside Views folder you can create the your customized layout which uses the css that you included in Content folder. And you can then include these layout in the views you later create inside shared folder of Views.
You can explore yourself by installing twitter.bootstrap.mvc4.sample from package manager console and see how your project changes.
This package changes your default layout to different layout, which is pretty cool.
Hope you can get idea of what is done and how you include your own layout from this above mentioned package.

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.

Render View (or Partial) In another project?

i have a solution with the following two projects - MyNamespace.Services and MyNamespace.Web.
Web contains a MVC web application.
In the Service project i have a EmailService class that takes care of sending out emails to the user.
I want to use either a partial or a view (ascx or aspx) for email templates.
I have found several solutions on how to render a partial view and get the result as a string which works fine if the template is inside the web project (as it is a controller in the web project that calls the email service).
(the 2 methods i am trying to use is either http://developersisland.blogspot.com/2009/01/renderpartial-to-string-in-aspnet-mvc.html (at the bottom of the blog) or http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/)
But my email templates are located in the Services project.
How can i refference the path to the templates (partial/view) in my Service project from inside the Web project, that works with either LoadControl or RenderPartial which both takes a virtual path as a parameter ?
It seems like no matter what i do the root directory is set to the Web projects directory.
Is it possible ?
Would be nice to be able to make it work independently of the web project somehow.
I don't think this is possible without developing your own view engine. The default view engine will only look in certain locations for the partial view -- which includes the current view folder and the shared views folder. I don't think you can search for views outside the current project since those views aren't registered with the view engine.
You can consider just creating your HTML helpers to render emails and return it as a string.
Doesn't really matter whether it is partial view or a method returning a string with HTML. i actually think that for your case helper methods would be a better choice.
A simple helper method is also more flexible in the ways you can use it.
You could try creating a custom view engine locator or virtual path provider. Here are a few examples that may help you get going:
Views in seperate assemblies in ASP.NET MVC
Grouping Controllers with ASP.NET MVC
How to use virtual path providers to dynamically load and compile content from virtual paths in ASP.NET 2.0
All of the links above are good, this might help as well. you will certainly be able to get it to find and use the views. The problem I had was in working with them, there was no code completion etc in the other projects. It was semi possible to get that as well by fiddling around with the project file but to be honest I ended up going with the Grouping solution above
Plug in architecture for ASP.NET MVC

ASP.NET MVC - Missing "Convert to Web Application" option

I created a new MVC project and added some webforms pages to it in an effort to start adding new pages to my app using MVC and eventually port the old pages over as well. Everything is building and working correctly but I did notice that I don't have the "Convert to Web Application" option when right clicking an aspx file. And I think its not regenerating my designer files when I change the controls on a page.
My guess is that the ProjectTypeGuid is wrong or in the wrong order. Can someone confirm?
Old (Webforms) project file
<ProjectGuid>{4F95C3D9-228E-4BD5-9840-46224BA3EBA7}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
New (MVC) project file
<ProjectGuid>{A4690D3F-695B-4BF4-93B7-EA5B17793051}</ProjectGuid>
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
This is so wrong on so many levels but I am going to answer you anyways in the hopes I might get an uptick or something. You have two routes with this. First route which I use all the time is put your mvc applications in their own projects. When your deploying the site drop the webforms application first, and then make a folder in that webforms application and put your mvc application into that folder. That should work like a charm for you. If you insit on having webforms and MVC Framework in the same project, then don't drop your webforms into the view folder. Create its own folder because you can not directly access your aspx pages from the views folder without making modifications to the web.config. Hope this helps.
MVC is available as a Web Project only. The VS2005 style Web Site is not supported.

Resources