How to get site context/information during the PreapplicationStartMethod - asp.net-mvc

When you run the same web based application as a multi-tenant application for different clients is there a way during the PreapplicationStartMethod to gain some kind of context to the site that is being started?
More specifically I'd like to get the host header information (the "bindingInformation" attribute value from the applicationHost.config); I have found ways to get this information at the time of a specific request long after the application has started. Is there a way to get the information during the application startup process?
This is an MVC 3 application and IIS 7.5.

I did not find the direct answer to this question for finding the "bindingInformation" at application start up. After reviewing the requirements further. The host header would not have been the best choice for my solution.
The the better solution is to use the System.Web.Hosting.HostingEnvironment.SiteName value instead.

Related

Which is better to make a web application offline -application cache or service worker?

I want to make my web application available even if network is not preset or when user is offline.
I searched about this and find two solution:
1) use Application cache
2) use Service worker
As service worker is in developing state and not supported by all browser so can not find this is a feasible according to my requirements.
On the other hand, application cache is about to deprecated(MDN site) from most of browser(still supporting in many browsers), I can not go with this solution too.
Please give some suggestion or correct me if I am wrong on above points.
Thanks in advance.
Your arguring is correct. Currently service workers are not supported by all browser and I doesn't look like Safari will support it in the near future, but at least it appears on their five year plan.
You can still use application cache, even if it doesn't have all the features sw brings and even if it will be deprecated. It is possible to have a sw / application cache mix on your site.
You have to compare the benefits against the work/money you want to put in your site to make it work offline. If you have an existing site you can check your browser stats and then make a decision.

Multi level sub Domains for a Multi-tenant Application

A project I am working on was once an internal intranet application, but now it is being ported over to a multi-tenant internet application. Usually, when deploying any web applications, we would use the format http://webapp.company.com which has existed long before I joined.
Since the project is now a multi tenant application, I am trying to decide between different architectures.
1) Using the client/tenant as part of the main host url
http://tenant.webapp.company.com
This approach requires additional ssl certificates and iis settings
2) Include the tenant as part of the routing and the tenant name will be included as a routing parameter
http://webapp.company.com/{tenant}/my/route/url/{param}
This approach, in my opinion, is 'messy' and I feel it is not the most-correct solution.
3) Keep the existing url of http://webapp.company.com and add specific bindings in IIS to point the requested url to the host location.
When the user enters the url http://tenant.company.com they will be served the application that resides at http://webapp.company.com The problem with this approach is that we may deploy additional applications and this is not scalable.
I am leaning towards approach number 1 as I have experience implementing it (without the extra domain). Is the 4th level domain ideal? Any ideas as to what approach is better than the other? Possibly a new approach? Any input is appreciated.
Using the client/tenant as part of the main host url
http://tenant.webapp.company.com
This approach requires additional ssl certificates and iis settings
Actually, you might be able to use a wildcard certificate for *.webapp.company.com, which would mean you can extend this scheme without additional IIS configuration.
In addition, this approach is the most elegant when it comes to routing. There is even a MVC-Subdomain-Routing project on GitHub that you can use for some direction (or as is if your requirements are met by the project).
Also see this question and this answer for some other approaches.

ASP.NET MVC website NOT in virtual directory

I have deployed three mvc pages to my server as virtual directories using IIS (which there are plenty of tutorials for). I need one of the apps to run when the base URL is requested. So, for example, I have a Help app which can currently be accessed via help.contoso.com/help but I want that app to run when a user simply goes to help.contoso.com instead. I gather there is some sort of redirect option but can't find an example for this type of request anywhere (they're all way more complicated and don't address my simple need). I also think there should be a way to just host the app as the 'root' web 'page' but can't find anything around that either...

bulk create user accounts to asp.net mvc3 membership tables in production environment

In dev environment I am using the ASP.NET configuration tool in Visual Studio to create a few users for testing. As I movel closer to QA and Production, I'm wondering what is the best way for me to automate the creation of a large amount (1000's) of users after application deployment.
I have a csv with all the usernames and passwords, roles etc. and I wan't to avail of the encryption and password salting security that is built in. I do not want to manually "Register" all these users.
I'm just not sure if this is something I can do (or instruct a db admin to perform for me).
Does anyone know of a way to achieve this?
Any assistance would be greatly appreciated.
Regards
The simplest solution would be to set up a "CSV Upload" form. The CSV would be processed by an MVC action calling Membership.CreateUser in a loop.
Probably, the performance of this will be good enough.
There's a few ways that I know of approaching a batch processing problem on an ASP.NET site.
Because of the wonky way an ASP.NET site's application pool can get recycled, batch processing is usually done on an external process.
Windows service
One way is a separate windows service, which gets the new excel and pumps that data in, and has a timer which keeps going around. I've seen this used often, and it is quite a pain, because it takes extra work to make it easily deployable.
Update ASP.Net membership from windows service
CacheItem
Second way is to use CacheItems and their expiration timers to do batch processing, what you do is you define a cache object with a long timer, and when that expires and the Removed-callback gets called, you do your database work. This is good because it deploys with your ASP.NET site, and you have your code in one logical place.
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
Workflow Foundation
Third way, is to make a workflow foundation service. That service gets a call from your ASP.NET site, which instantiates a WF service, that does some db work with your excel file, and then it goes into a while-loop with a delay of a month in it. This is good, because it is not tied to the lifespan of your ASP.NET application pool - you get more control, and this logic can be separated into a different IIS hosted WCF service.
http://msdn.microsoft.com/en-us/library/dd489452.aspx
Integrating with data is always a pain though, remember that the solution that gives you the least work and least chance of failure when deploying is the best solution.

Is it possible to restrict access to Reporting Services over HTTP by ip address?

I'm trying to deploy my Reporting Services application to a remote site. I'm using url access and I want to impersonate a user based on an ip address range.
Is this possible?
Maybe by putting some firewall rules between the reports server and the client you could stop deny/allow certain ip addresses, but i've never come across anything like that built into reporting services
There isn't anything like that built into Reporting Services. But I can think of a couple of alternatives.
Usually the Reporting Services website and web service are running under IIS. You can configure IIS to block access by IP address. Depending on what version of IIS you are using, the instruction may vary. I would just google it. This would be the easiest way in my opinion.
First thing to note is that I haven't tested the second way, it is just an idea. Since the Reporting Services website and web service run under Asp.Net, in theory you could create a custom IHttpModule and add it to the web.config. Hanselman has an nice article about coding up such a IHttpModule and configuring the web.config here.
This is an old post, but we are trying to do the same thing. Firewall is the way to do it - SSRS doesn't use IIS, so it isn't possible through IIS.

Resources