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.
Related
I Created empty project in mvc6 but theres is no mvc folders , how i ceate model,view,controller folders ?
Because an Aspnet core empty project is truly empty. It is up to you to go about making it.
If you notice it's not just the folder but some of the most used middlewares will also not be there such as app.MVC and app.usemvc in your startup.cs class. The purpose of an empty project is to give you complete control over what you need or don't need.
If you know you definitely need MVC then I suggest you use the ASP.Net MVC template that comes with all the folders and goodies you will need to run MVC.
As for MVC folder structure; controllers and models don't need any special folders. That's just a convention. But views do. So you need to have a Views folder at least.
A new MVC Web application has been created with Empty Razor Template. In this template I found that default controller,Model and View are missed. I need to change the template from Empty to Internet Application.
I couldn't find any option in the properties to change Internet controller. How can I do that without creating a new project?
You could create a new project in reverse. Create a new project based on the Internet template, and use a compare tool (I rely heavily on BeyondCompare) to merge the Internet template differences into your existing project.
The difference between Empty Razor Template and Internet Application Template is in two (Account and Home) Controllers, Views that go with them and in different Site.css. You can't simply "switch" between templates.
You can go from Internet Application to Empty, if you delete Account and Home Controllers and corresponding Views. Other way around is a bit more difficult. Use scaffolding to accomplish that.
You can also check differences between templates here.
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).
How do I enforce an asp.net mvc application to point to the subfolder instead of root folder.
Lets say I have website called: http://mywebsite
I have got totally different asp.net mvc applications called UserApp and CustomerApp. There is no common thing between them. Now, I want to deploy the application like:
http://mywebsite/UserApp/SomeController/SomeAction
http://mywebsite/CustomerApp/SomeController/SomeAction
I deployed the application above ways. But, after deployment, only home page works. Any other nested controller/action still points to root path instead of specific path.
You probably need to set both subfolders as applications in IIS.
The answer from Slaks is not enough, as default MVC routing is "/controller/action" from the web root.
You could use the IIS routing module to rewrite paths so that http://yourWebSite/UserApp/SomeController/SomeAction is rewrited to http://yourWebSite:8080/SomeController/SomeAction and setup 2 websites on different ports internally.
Or you could modify mvc route mapping. It could work, ... or not. Search for "MapRoute" in MSDN.
Or you could create 2 websites with 2 different hosts.
This is not unusual for 2 unrelated websites :=)
I built a small module in ASP.net MVC which consists of
a javascript file
a css file
a razor partial view
a c# model class
If I use the standard way to manage the files, I have to spread them in these folders:
/Scripts
/Content/css
/View
/Models
I know that MVC is for separating them and it's fine for the application but i my case I would be happier to have all files somewhere together.
There are area's in MVC but I think that's to big for a small module. All I want is to build a small package in my application for the files of this module.
Any good approach for this? How do you handle this?
/Scripts
/Content/css
/View
/Models
This is just the structure that the default asp.net mvc project template imposes.
You can have any structure you like, but I would recommend keeping your Views and Model separate.
Since our "Model" usually sits in a different assembly our MVC project structure is normally:
Application (all application infastructure code)
Content
css
images
scripts
Controllers
ViewModels
Views
Again this is personal preference but I typically like to keep my static assets (css,images,scripts) under one directory.
You can of course separate things out even further. For example if we're using a javascript plugin that has it's own "core" css and images then we normally keep these together e.g.:
Content
css
images
scripts
libs
myplugin
myplugin.js
myplugin.css
myplugin.png
Of course as you split things out in this way it can become hard to manage. For this reason we use Client Dependency Framework. You could also try Cassette.