Host MVC under SharePoint in IIS

How to Hos MVC solution under SharePoint in IIS Step By Step

How to Hos MVC solution under SharePoint in IIS?

In certain scenarios, you might need to host several MVC applications as subdirectories under the main domain of a SharePoint web application, without having to open additional ports or create additional subdomains.

In fact, the IIS integration allows you to host multiple applications under the same domain name and port, without without needing to set up distinct subdomains or open extra ports. However, this might pose more challenges when dealing with an existing SharePoint web application.

Host MVC under SharePoint in IIS
Host MVC under SharePoint in IIS

In this post, we will walk you through the detailed steps to learn more how we can host a new application under SharePoint web application in IIS.

Add Application under SharePoint Web Application in IIS

Prerequisites of Host MVC Application under SharePoint IIS

To host an MVC application under SharePoint IIS, the following prerequisites must be met:

  1. IIS must be installed and configured.
  2. A SharePoint environment already set up.
  3. Have access to the SharePoint server and permissions to manage IIS.
  4. The MVC package is ready.
  5. The DB Server is ready and the new DB is restored.

Steps to host an MVC application under SharePoint IIS

To host an MVC application under SharePoint IIS, you have to do the following:

  1. Prepare the MVC Package.
  2. Configure IIS.
    • Create a new Application Pool.
    • Create a new Application under SharePoint Site.
    • Adjust Permissions.
    • Break parent Web Config settings.
  3. Review the web config of the new web application.
  4. Test the new application.
  5. Deploy the new application on all SharePoint Servers.

Step 1: Prepare the MVC

Before deploying your solution to the SharePoint server, you need first to complete the following steps:

  1. Ensure that your solution works as expected independently of SharePoint.
  2. Publish your MVC application to a folder on your local machine.
  3. Copy the contents of the published MVC application folder to the SharePoint server.
  4. Place the published MVC application folder in a directory accessible by the SharePoint application pool account.

Step 2: Configure SharePoint IIS

After preparing the MVC solution package, you must configure the IIS settings on all SharePoint servers in your farm by following these steps:

  1. Create a new Application Pool.
  2. Create a new Application under SharePoint Site
  3. Adjust Permissions
  4. Break inheritance of Web Config settings
1) Create a new Application Pool

To create a new web application Pool, you have to do the following:

  1. Login to the SharePoint Server.
  2. Open IIS.
  3. Right Click on “Application Pools“, and Select “Add Application Pool“.
Add new Application Pool in SharePoint
  1. Provide a name for the application pool that suits your preference, and leave the default adjustments as described below.
Create new Application Pool in SharePoint
2) Change the Application Pool Identity

By default, the application pool identity for the newly created application pool is set to “ApplicationPoolIdentity.”

However, to ensure that your MVC solution functions properly under the SharePoint Web Application in IIS, I recommend using the same Application Pool Account that is currently used for the parent site.

To change the Application Pool identity, you have to do the following:

  1. Right click on the newly created Application Pool > select “Advanced Settings“.
Change Application Pool Identity
  1. Scroll down to “Identity“, and click on the three dot button as stated below.
Application Pool Identity
  1. Provide the same credentials of the Parent Application Pool Identity Account.
Application Pool Identity UserID
3) Create a new Application under SharePoint Site

Now the application pool has been created and is ready for use, the next step is to create a new Application under SharePoint Web Site in IIS by doing the following:

  1. Open IIS > Expand “Sites“.
  2. Right Click on your SharePoint Web Site, and select “Add Application“.
Add Application under SharePoint Web Application in IIS
  1. A new dialog will open where you need to provide the following:
    • Alias: Name of your Application without any space.
    • Application Pool: Select the newly created Application Pool.
    • Physical Path: Set the physical path to the directory where you copied the MVC application.
Create Application under SharePoint Web Application in IIS
  1. Click on “Test Settings” to ensure that the Application Pool Identity account has the permissions required to connect to the specified path.
Test Connection Application in IIS
  1. Then Click OK.
4) Adjust Permissions

If you encounter a permission issue when testing the connection in the previous step, it indicates that you need to adjust the permissions for your application folder.

You should grant the Application Pool’s Identity the necessary permissions on the folder that hosts the MVC package.

To adjust the permissions for the application folder, you have to do the following:

  1. Right click on the newly created application.
  2. Select “Edit Permissions“.
Edit Permission in IIS
  1. Click on the “Security” tab, and provide the the account that you have set in the “ApplicationPoolIdentity” property, a “Modify” permissions as stated below.
Grant Permissions in IIS
5) Break inheritance of Web Config settings

This step is crucial, and it needs to be done to ensure that your MVC application functions as expected, without inheriting the Web.Config configuration from the parent SharePoint Web.Config file.

To break the inheritance for the web config from the parent site, you have to do the following:

  1. Open “CMD” as Administrator.
Host MVC under SharePoint in IIS
  1. Type “CD inetsrv” to navigate to the Internet Information Service Folder.
  1. Enter the following cmdlet, replacing “YourApplicationPoolName” with the actual name of your application pool. This will enable your MVC application to read the web config settings from its own configuration file, rather than inheriting them from the parent configuration
appcmd set config /section:system.applicationHost/applicationPools  /[name='YourApplicationPoolName'].enableConfigurationOverride:"False" /commit:apphost
break web.config settings

Step 3: Review the .Net Target Version

The final step is to review the Web Config File entries for the newly created application such as:

  • Target Framework Number
  • Custom Keys
  • Connection String

In case the current SharePoint environment doesn’t have the same Target Framework Number , so you have to change it to “4.5” to get it working with current installed version.

In my case, the Target Framework is “4.8” which is supported by SharePoint 2019/2016 and already installed in the current SharePoint environment.

Change dot net Framework Target

Don’t forget to grant the Application Pool Identity account an “Owner” permission for the Database on the DB Server, also make sure that the SharePoint Server can reach the Database Server as mentioned at How to Check SQL Server Connectivity between Application Server and Database Server

Step 4: Test the MVC Web Application

Before applying the same steps to other SharePoint Servers, it’s crucial to test your current application locally and address any issues that may arise, including:

  • If you encounter issues with DLL version mismatches, make sure that all required DLLs are consistent and match the expected versions for your application to function correctly.
  • Ensure that any custom keys in your Web Config are updated as needed to align with your specific application requirements.
  • If the connection string is not updated. Please note that if it doesn’t work with Windows Authentication, you can try using SQL Authentication instead.

Conclusion

In conclusion, hosting an MVC solution under SharePoint in IIS involves several crucial steps:

  1. Create an Application Pool: Establish a dedicated application pool for your MVC application in IIS.
  2. Configure SharePoint Web Application: Create a new application under the SharePoint web site in IIS, specifying the relevant settings.
  3. Test Permissions: Ensure that the Application Pool Identity account has the necessary permissions to access the application’s folder.
  4. Separate Configuration: Adjust the MVC application’s settings and configuration to prevent it from inheriting settings from the parent SharePoint web.config.
  5. Check Target Framework: Confirm that the target framework of your MVC application aligns with the SharePoint environment. Modify it if necessary.
  6. Database Permissions: Grant the Application Pool Identity account “Owner” permissions for the database on the DB Server.
  7. Local Testing: Thoroughly test your application locally to identify and resolve any issues before applying the same steps to other SharePoint Servers.
  8. Consider Authentication Methods: If Windows Authentication doesn’t work, consider using SQL Authentication for database connectivity.
  9. Update Custom Keys: Ensure that any custom keys in your Web Config are updated correctly to match your application’s requirements.
  10. DLL Version Matching: Verify that DLL versions align with your application’s needs and address any version mismatches.

Hosting an MVC solution under SharePoint in IIS can be a complex process, but following these steps will help you successfully integrate your MVC application into the SharePoint environment.

See Also

1 thought on “Host MVC under SharePoint in IIS”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top