I am trying to achieve the following in an MVC5 app.
In the MVC site root, the is a subdirectory "Sites" where static files live. For instance, there might be static assets (HTML, JS, CSS) for "acme" and it is located under "/Sites/acme/"
Ideally, if you hit "acme.localhost" (in my dev environment) it will serve the contents of the /Sites/acme location, defaulting to index.html. So basically everything on the subdomain of acme will be rewritten to be relative to /Sites/acme. I have the DNS side of this all sorted out.
I know the IIS URL Rewrite module is designed to do this scenario, however the catch is users can define their subdomain in my MVC app dynamically (these are currently stored in a database). I don't know what they will be, and as far as I understand editing the rewriting in web.config if I were to do it this way will cause the parent MVC application pool to recycle. This makes me think it has to be some sort of HttpHandler that looks at a cached table of possible subdomains registered in the system and rewrites accordingly.
Any thoughts or suggestions? I was thinking a HTTP module or custom Route handler but not sure how to achieve this, and am very wary of doing this in an efficient way.
Thanks
Related
We have a regular asp.net website. I started debugging several errors, so the website cannot be used (but is not down). Since the default page is not Default.aspx and users are used to going directly to Main.aspx, if anyone goes to http://network:1332/Main.aspx, the person should be redirected to Issues.htm.
Is there an easy to do this without having to alter Main.aspx or write any code? Maybe change web.config or some IIS 6 configuration?
I just don't want anyone to use the website even though the site is available for use.
Thanks.
If you have an ASP.NET web application site, and you place a text file
named "app_offline.htm" in the root of the site, all requests to that
website will redirect to that app_offline.htm file. Basically, if you
need to take an entire ASP.NET site offline, you can place some nice
message in that file.
https://forums.iis.net/t/1152788.aspx?Put+website+in+maintenance+mode
Be warned you too will be directed to the maintenance page, so if you're debugging in production this could make things more difficult.
You can use Url Rewrite Module to IIS. Then you will be able to define your rewrite rules in web.config or using IIS Manager. Check this : https://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
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.
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 have two web sites in IIS like
http://domainA.com
http://domainB.com
I would like to use the same code for these web sites but a different web.config files. Is this possible? I store database connectionstrings etc in the web.config files, all the other code in the applications are the same.
I have tried some different approches with creating a folder structure like
-Root
- Domain A
- web.config for domain A
- Code
- Virtual Directory to Source Code
- Domain B
- web.config for domain B
- Code
- Virtual Directory to Source Code
- Source Code
I will then point the website for domain A to "Root/Domain A" and domain B to "Root/Domain B" but the problem is then that the code must be accessed one level down, like
http://domainA.com/Code/
http://domainB.com/Code/
Any ideas?
I will base my answer on the assumption that you are writing custom code rather than using an out of the box solution such as DNN or SharePoint.
One solution that comes to mind to keep a common code base is to maintain your website specific configuration settings in your database instead of the web.config. You can keep your database structure fairly dynamic by using a set of name/value pairs. You would of course need to take this into account in the design of your application and plan for it in your database. This gives you the advantage of only having a single code base as well as a single web.config. If you need to maintain content in separate databases for each site, the connection string info to those content databases can be one of the name/value pairs in your configuration database.
You can even take this one step further by having a single website in IIS for all domains as well (unless you will be using SSL, in which case separate IIS sites would be better). You would need to add host headers to the website and then look for the host header in your code to determine what settings to use and what content to serve. You would lose the ability to create separate app pools so you should check your requirements if this is a feasible option for your situation.
This is actually a similar model to how both DNN and SharePoint work but can certainly be done in a custom application as well.
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.