Good morning,
I have a fairly large MVC project with 30/40 controller and a lot of views, i am trying to publish on IIS using multiple application so i can split various sites per different customer.
I want to use my landing page as the base url:
https://somewebsite
I then want to host multiple applications (e.g the same project with different config) as separate applications but under the same main host name.
https://somewebsite/Customer1
https://somewebsite/Customer2
Now i can get my multiple websites fine under the seperate host as application, but when i add my landing page (as the full application) its corrupting the other two sites.
My thoughts are that the routing in the route app (the one i want just for landing page is causing the issue).
Any ideas?
If you are deploying via WebDeploy it will delete subfolders under the host site if they are not part of the host application. You can disable this behavior however with a MSBuild argument:
/p:SkipExtraFilesOnServer=true
OR during the MSDeploy deployment using the following argument:
-enableRule:DoNotDelete
http://www.dotnetcatch.com/2016/02/01/webdeploymsdeploy-quick-tip-keep-existing-files-during-deployment/
The issue lay within the web.config of the applications. The config was being inherited from the master site and causing issues across the board.
Set the clear attributes in the child application config and all is well with the applications.
Related
I have to create a Web API for my existing MVC project and make API Controllers calling the Service Layer and Models, which is contained in separate projects but in the same Solution, then create and map to DTOs.
Layout of my Projects Solution in VS
( ignore the BookService.cs. I was just trying to do a WebAPI tutorial and I put it in the same solution temporarily).
I have been reading up on WebAPI and how it functions for the past 2 days, but I am not being able to fully grasp an understanding on how to create a API Controllers for my MVC project without referencing it? I also have to make Views at the end, in my main project calling the uri, but I am very confused at this point.
It would help me out a lot if someone can please clarify how I am to tackle this or point me to a tutorial or some sort of source to learn the process of working with Web API. Thank you.
The Web Api project will be a separate "website", that you will need to host individually. Your MVC project will make requests to the Web Api using HttpClient.
Since the Web Api will be separate, you won't be able to utilize helpers like Url.RouteUrl, etc. to get URLs for the Web Api actions. You will also just need to know the full URI to the Web Api, including it's domain. There will be no way to programmatically ascertain this information, so I would recommend making use of Application Settings to avoid hardcoding in your MVC project.
Right-click on your MVC project in the Solution Explorer and choose Properties. Then click over to the Settings tab. Here, you can add strongly-typed settings that your MVC application can utilize. Importantly, these settings are still persisted in the Web.config, so you can change them using config transforms. Your Web Api will likely have different URLs depending on whether you're in development vs. production, for example, so that will make it very easy to ensure that you're hitting the right thing in the right environment.
You can add a setting like WebApiUri, and give it a type of System.Uri. Then, set it to the string value of where your Web Api is hosted in development, i.e. http://localhost:12345. It's important that the setting be specific to your development environment, as config transforms are not applied in development. For staging, production, etc. you'll change this setting appropriately in the applicable config transform, and it will be updated to the right value for the right environment when you publish.
Then, when you need to work with it, you'll just do something like:
var client = new HttpClient();
client.BaseAddress = Properties.Settings.Default.WebApiUri;
Then, just make requests as normal through the client. For more information on working with HttpClient, see the documentation.
Can I configure IIS7 to run the actions of two separate controllers under two separate routes in different app pools?
Using old .svc web services, I could separate service calls by having a separate .svc file under a particular directory, whereby I could make the directory a Virtual Directory allowing me to run the service as a different identity (or with different authentication settings). This gave me the ability to have a single code base deployed to separate web structure locations.
I now have a single MVC (/WebApi) application, with multiple service APIs. Some of these service calls have to be run in a different app pool from the rest for security purposes.
Despite being separate service methods on separate routes within the application, IIS only sees it as a single application, and (apparently) has no way to map the virtual routes within MVC to Virtual Directory settings.
Creating a separate MVC application and hosting it in a Virtual Directory under the root site causes issues around web.config inheritance, which again I haven't found a way around.
Having said all this, my knowledge of IIS7 is very limited, and googling just brings up posts based on keywors that don't cover this particular scenario.
Would appreciate any help.
Regards,
Rob.
Web.config is inherited in directories and virtual directories, but not across applications. Please make sure your subdirectory is set up as an application (right click on parent, select add application or right click on sub directory and select "convert to application"). At this point each application has it's own web.config file.
I have to deal with a legacy asp.net mvc web app (.net 4). It uses some customized routing, which works fine when I use visual studio 2010's development server. However, when I use iis instead (during debugging) it does not seem to work (never used iis during debugging before).
The answer provided here does not seem to help. I already use:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Is there any other reason why the routing may not work? Thanks!
A generic post, unfortunately Internet Information System can create a slew of configuration issues. This is quite possibly it's largest pitfall. Is when you launch it on a Deployment Server, Local Server, or a Production Server the outcome may never appear to be the same.
I'll use Internet Information System Six, because it is similar to Seven and Eight but it just lacks certain features.
Inside of your project for ASP.NET MVC Web Application you'll want to right-click your project and select Properties.
You should see a tab that indicates the word: *Web**
Inside this tab towards the bottom you'll want to ensure that Use IIS Web Server is selected.
You'll want to put a Project URL in there.
This field should look like: *http://localhost/ApplicationName*. What your essentially doing here is mapping your project directory for IIS. You see each IIS Site stores a site inside the:
C:\inetpub\wwwroot
That is your Root Site Folder, where IIS will reference all of your Site Components. ** Keep in mind this Virtual Directory in projects is actually different then your IIS Configuration item listed. **
Now you'll want to open Internet Information System, you'll want to setup your File Extensions. So before doing anything in IIS, you'll want to configure your ASP.NET MVC Installer. You need to configure your mappings (ISAPI) to the .mvc extension to aspnet_isapi.dll. This step is required in order for IIS to hand off Routing Request using the .mvc extension to ASP.NET.
From a good blog post he stated:
If you’re planning to use extension-less URLs, you can skip this
section, but it may be useful to read anyways as it has some
information you’ll need to know when setting up extension-less URLs.
Mapping .mvc to ASP.NET
If you plan to use the .mvc URL extension, and are going to deploy to
IIS 6 on a machine that does not have ASP.NET MVC installed, you’ll
need to create this mapping by performing the following steps.
One nice benefit of using the .aspx extension instead of .mvc is that
you don’t have to worry about mapping the .aspx extension. It should
already be mapped assuming you have ASP.NET installed properly on the
machine.
For the rest of you, start by right clicking on the Virtual
Application node (IIS6DemoWeb in this case) and select Properties. You
should see the following dialog.
Make sure your in the Virtual Directory Tab and select Configuration. This will allow changes to the root website. This should bring up your Application Configuration Dialog. That will allow you to physically map your application. Since your using .mvc that is what you'll select.
If .mvc isn't found in the list, you can point to the Data Link Library here:
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
Now before you run the application you need to update the default routes, that way they look for the proper file extension. In your Global.asax.cs you'll want to ensure your using .mvc extension.
You would implement a method such as:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.mvc/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}
That should allow the site to properly display. This is a very, very generic and broad example. But hopefully this points you in a good direction.
Update:
When utilizing Internet Information System Seven you have to be aware of the following:
Site Configuration
Application Pool
Database Configuration
Those three items are common culprits to incorrect configuration.
A really wonderful blog can be found here:
Another nice article can be found here:
However, this article should hit the nail directly on the head for you:
As I stated the above detail should resolve your issue. But, with the introduction of IIS 7 they have two completely different methods to allow request: Integrated and Classic.
The major difference is Integrated will perform better and includes more features. Where Classic is designed for backwards compatibility. Your route request processing method is determined by your Application Pool. With this incorrectly configured; it won't work.
Launch the Internet Information Services Manager
In the Connections window, select an application
In the Actions window, click the Basic Settings link to open the Edit Application dialog box
Take note of the Application pool selected.
By default, IIS is configured to support two application pools:
DefaultAppPool and Classic .NET AppPool. If DefaultAppPool is
selected, then your application is running in integrated request
processing mode. If Classic .NET AppPool is selected, your application
is running in classic request processing mode.
From within that box you'll be able to modify the processing mode within an "Edit Application Dialog Box".
Hopefully this additional information better assist you for your goal. The first two blogs are a avoiding IIS, where the third one focuses specifically on IIS 7. If you have any questions let me know.
I have 1 secure MVC website already hosted at say https://mysite.co.uk. This website has areas, controllers and actions as per normal:
https://mysite.co.uk/kitchen/create
https://mysite.co.uk/bathroom/edit
etc
Initially, I was told that my second MVC website would be able to be hosted under a new url: https://mysite-newsite.co.uk, so I have a new solution with.
But now unfortunately the deployment team have said it needs to be deployed under the initial main url:
https://mysite.co.uk/newsite
We are using iis7 and I have tried to achieve this using Add Application , but I just run into lots of problems with routing, nhibernate dll conflicts etc.
Can this be actually be resolved somehow in iis7 please? Or will the second MVC solution need to be re-written somehow?
Thanks
I think your best bet would be to create a sub-directory in the first application's deployed directory and put the second application there.
You can then set the sub-directory to be its own application in IIS and they will operate independently.
So, you will have url's like this:
https://mysite.co.uk/kitchen/create <-- first site
https://mysite.co.uk/[subdirectory]/controller/action <-- second site
The route urls in the second application should work, but you will need to check this.
Otherwise, you will have to merge the two applications into one solution.
I'm trying to make an application that can host multiple ecommerce front ends, so I need to figure out how to route all requests to one class which then parses templates and handles all output.
So my question is then how do I route all requests to one class?
In PHP I would use mod_rewrite and have all requests go to index.php and add "main = new MainClass();", but I have no idea on how to achieve this with ASP.NET
The MVC framework isn't what I'm looking for, since I will host several domains with one system.
It sounds like what you want is an HttpModule. (Sorry for the Google link, but there's a lot about this out there and I'm not sure which is the best resource for you.)
Essentially, what an HttpModule does is intercept requests between the web server (IIS) and the application (ASP.NET).
You can use the Route class to register route handlers for all of the routes you define. Basically, you would create one instance of an implementation of IRouteHandler (or different instances of the same type) for all the permutations of the urls on your site.
Also, it should be said that following statement that you made is misguided:
The MVC framework isn't what I'm
looking for, since I will host several
domains with one system.
Any problems or limitations you would run into hosting several domains in one system with MVC will be apparent in ASP.NET as well; MVC sits on top of ASP.NET, not separate from it.