accessing multiple virtual directories using a single web app - asp.net

Is it possible to look into multiple virtual directories, using a single web application?
I'm trying to develop a web app; which can create a site, save this site to a virtual directory in the same server, and make changes (i.e. add/edit webpages).
The web app will handle multiple domain names (IIS will handle the bindings going into the single web app), which are routed by the web app to their respective virtual directories.
Can anyone point me to the right direction?
Thanks!

First of all, you need a certain permissions in order to manipulate the IIS metabase. The default ASP.NET user account doesn't have such permissions so you might want to use an impersonation. You can read more here (what is impersonation) and here (how to impersonate programmatically).
To configure the IIS programmatically use the classes from the System.DirectoryServices namespace. You can read more about how to do this here (tagged as for IIS6). You can also use the Microsoft.Web.Administration namespace (which seems more specific to IIS7) but in this case you need to download and install the corresponding SDK.
Hope I clarified things for you a bit.

Related

How to create an installer for ASP.net website with NSIS

I want to create an installer for ASP.net website.
Can I use NSIS to create an installer for my web application.
So I wanted to do followings through the installation wizard.
I need to install required databases in client computer.
I need to update the connection string in web.config file based the database.
I need to create ODBC connection and save their names in my project config file.
I need to create an application in application pool of IIS.
I need to host my project in IIS.
Can someone please let me know is it possible to do those things with NSIS?If possible how can I do it?
Thanking you.
There is no exact answer for you.
You need to create a customized installer with custom pages - but it is up to you how the custom pages look like and what they do.
You can achieve this with NSIS (even with Inno Setup which is a little easier to user) but we cannot post tutorial for you.
What you need to do is to start with simple installer (default one) and add custom pages to it. It page represent some functionality:
settings database connection values
writing configuration
creating app pool
setting IIS (there are some NSIS plug-in for working with IIS)
copying files etc.
Start with some NSIS example and add more and more functionality in it until it meets your requirements.

Creating symbolic links for IIS7 web environments

. .
We have a growing need where web resources (files, documents, images, etc.) need to be shared between different web environments.
I'm looking into setting up symlinks to support this, but I don't know how to set it up. (Or would it be better to set up virtual directories? Part of my question is, what are current best practices to set this up?)
For example purposes, assume:
The environment is running on an IIS7 platform, and MUST be in a Windows environment.
The shared files need to be maintained using TFS.
The web sites occupy different sites on the same IIS instance and reside on the same physical server.
The sites are multple web platforms -- for example, one site is ASP.NET, while another is running classic ASP.
All sites are under the same corporate umbrella, which is why resources need to be shared.
All sites pull data from the same SQL Server database instance.
How would I set up a symlink to support this? Or, for that matter, are symlinks the best way to go about this?
Thanks in advance!
Edit: Addendum to the above example: my classic ASP environment can also include ASP.NET virtual subfolders. For example, I can have my domain www.somedomain.com running in classic ASP, but have a subdirectory (www.somedomain.com/dotnetapp) running as an ASP.NET application. The virtual directory used by the ASP.NET must be able to access the same file resources as the classic ASP environment.
On Windows virtual directories are more the standard way to do this. It also allows you to use IIS' virtual directory features and Windows/IIS rights management.

Best place for ASP.NET web application logs

What is the recommended folder to write the web application log files?
c:\inetpub\wwwroot\Logs, App_Data folder... ?
I prefer App_Data which is always writable by design and closed to access from the browser by ASP.NET filtering module.
You should consider keeping your logs on a separate drive to the one that contains your Windows installation. This is because it is possible for your log files eventually to use all the space on your system drive, at which point your server will stop responding - keeping logs on a separate drive avoids this issue.
There is no standard location for application logs. Use what you and your team agree on.
IIS 6 logs normally live in %WINDIR%\Logs.
IIS 7 seems to default to %SystemDrive%\inetpub\logs\LogFiles.
You may need to give special permissions to that folder , so make sure (for security reasons) it resides outside the web application folder
This really depends on you where you want it to store. i will recommend you to use elmah
(Error Logging Modules and Handlers for ASP.NET) which gives you flexibility to handle logs
Chetan
http://chetanwarade.wordpress.com/

ASP.NET file system permissions

I always thought the user running the app pool was used to, for instance, access the file system when an application is trying to write a file.
I have an application in IIS, setup with Windows Integrated Authentication, that tries to write a file to the file system. I always get an error unless I give permissions on the file system to the specific domain user that logged in through Windows Integrated Authentication.
Any reason why I´m observing this behaviour?
Thx in advance
Are you using Impersonation? This would use the User's identity to do stuff, rather than the one of the AppPool. If you're using a third party ASP.net Application, check if they use Impersonation (for example, SharePoint does).
There is a way to revert the identity of the AppPool. Check this question which includes the RevertToSelf and HostingEnvironment.Impersonate methods. The Question is about SharePoint, but these two answers are the non-SharePoint way of reverting to the apppool, so they apply.

Write to file not working after hosting (publishing the web application) ASP.Net

Writing to a file is not working after hosting the web application, whereas they were working while developing and testing in my localhost on debug mode. What could be the problem in writing to a file after hosting? Is there any special permission that should be given to the folders/file?
Without knowing the OS version or the code you're trying to use, I'd say the most likely culprit is permissions. The ASP.NET user (which varies based on version of Windows) needs write access to the folder you're trying to write to. This is likely not enabled by your host.
Yes, you will need read, write, and modify permissions to the directory you wish to write to. You need to ensure that the account under which ASP.NET is running has those rights set up.

Resources