Virtual directory settings in IIS 8 - asp.net

How to set the Application Pool for a Virtual directory in IIS 8 on a Windows 2012 server?

Application pool can be set to an application and not to a Virtual Directory.

The following steps will create an application pool named TestPool.
Open Internet Information Services Manager.
Click Start > All > Accessories > Run.
In the Open box, type inetmgr and click OK.
Expand .
Right-click Application Pools and select Add Application Pool.
Provide the required details on the Add Application Pool dialog box.
Name: TestPool
.NET Framework version: NET Framework< Version>.
Managed pipeline model: Integrated
Start application pool immediately: Checked

You need to first convert your virtual directory to application first. For that right click on virtual directory then select "Convert to Application".
In Add Application dialog box, default application pool is shown here, if you want to change it you can change by clicking the Select button.
Select the pool required and save the changes made.

Related

Hosting an asp.net website in my computer

I have an app I am modifying for a client. The app is in asp.net. I have read that I can deploy the app in three ways:
xCopy Deployment
Precompiled Deployment
Web Setup Project
I would like to go with xCopy method. I have not installed visual studio but have SQL server installed.
Coming from a PHP background, is IIS just like apache where I can copy my files inside a directory in IIS and launch the app in a web browser or is there an extra step that required to be able to run the asp.net web app?
Here is a complete guide to:
Install IIS in windows
Install SQL Server Express
Publish to IIS in Visual Studio
Finally, test in the test environment
Note: There is no need to install IIS, just enable its some settings. And you have to install SQL Server and Visual Studio.
Edit:
Install IIS
Open Control Panel, Programs and Features, Turn Windows features on or off.
Make sure that ASP.NET 4.5 is selected under Internet Information Services -> World Wide Web Services -> Application Development Features.
Set ASP.Net Framework from v2.0 to v4.0: Press Windows + R and type "inetmgr" hit enter.
In the Application Pools pane under connections, click DefaultAppPool, and then in the Actions pane click Basic Settings.
In the Edit Application Pool dialog box, change .NET Framework version to .NET Framework v4.0.30319 and click OK.
Install SQL Server Express
Download it from here either x64 and x86 based.
After downloading SQL Server run the setup and click New SQL Server stand-alone installation. In the installation wizard accept the default settings.
Publish to IIS in Visual Studio
Run Visual Studio as Administrator by Right - Click on VS icon.
Right - Click on your project select Publish, in Publish Web create new Profile.
In Connection tab enter localhost -> Service URL, Default Web Site/yourProjectName -> Site/application, http://localhost/yourProjectName -> Destination URL
In Settings tab check Exclude files from the App_Data folder.
enter Remote connection string that you have use to connect with SQL Server database.
Check Update database and click Configure database updates add sql script Grant.sql that you will run in SQL Server which is like:
IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOL\DefaultAppPool')
BEGIN
CREATE LOGIN [IIS APPPOOL\DefaultAppPool]
FROM WINDOWS WITH DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [ContosoUniversityUser]
FOR LOGIN [IIS APPPOOL\DefaultAppPool]
GO
EXEC sp_addrolemember 'db_owner', 'yourProjectName'
GO
Finally click on Publish.
Test in Environment
Check that your project files have exits in wwwroot folder at C:\inetpub\wwwroot\yourProjectName. Run your project index.aspx file and test it.

"AlwaysRunning" not working

We have IIS version 6.2 for running an ASP.net application.
We have a application pool for this web application.
The .net framework version is "4.0".
"Startmodus" is "AlwaysRunning".
Why is the first access of a user always slow?
I found several questions releated to this topic but I cannot see why "AlwaysRunning" is not helping here.
Is it a good idea to create a powershell script accesssing the web application every 15 minutes in order to avoid this "IIS sleep mode"?
a little late to the party, but it seems what you need is either set the Idle Time-out to zero (default is 20) means every 20 minutes the application pool will be restarted. Source
Also there is a tag in web.config, to tell iis to send a fake request to you app at start up , to make sure you app is completley initialized :
<applicationInitialization
remapManagedRequestsTo="Startup.htm"
skipManagedModules="true" >
<add initializationPage="/default.aspx" />
</applicationInitialization>
Source
I had to install the 'Application Initialization' feature of IIS (only IIS 8+ I think).
https://www.iis.net/configreference/system.webserver/applicationinitialization.
Furthermore I had to set following settings:
App pool: StartMode always running
The page: Preload enabled
And finally recycle the app pool for the changes to take effect.
AlwaysRunning means that it won't shut down if it's idle.
So, you need to configure Auto Start as well:
In IIS Manager, click computer name in the Connection pane.
Switch to Features View if the view is not active.
Double-click Configuration Editor in the Management section of the
Features View.
Click the down-arrow for the Section field, expand
system.applicationhost, and then click application pools.
Click (Collection) and then click eclipses (…) next to the field
that shows the count.
In the Collection Editor, select the application pool for which you
want to configure the startMode attribute.
In the Properties window at the bottom, set the value of autoStart
attribute to True.
Complete info here

How to config application pool in IIS 7.5 automatically re-start when it was stopped?

My website was down several times per day and when I check the application pool (IIS 7.5), I saw it was stopped and I must restart it manually. How can I setup application pool so that it automatically restarts after an error?
You will need to change the startMode for the application pool your website is running on from onDemand to AlwaysRunning. By default IIS sets all application pools to onDemand.
In IIS Manager, click computer name in the Connection pane.
Switch to Features View if the view is not active.
Double-click Configuration Editor in the Management section of the Features View.
Click the down-arrow for the Section field, expand system.applicationhost, and then click application pools.
Click (Collection) and then click ellipses (…) next to the field that shows the count.
In the Collection Editor, select the application pool for which you want to configure the startMode attribute.
In the Properties window at the bottom, set the value of startMode attribute to AlwaysRunning.
Source: http://msdn.microsoft.com/en-us/library/ee677285%28v=azure.10%29.aspx
In IIS 8 and above, the start mode setting is now directly available from the Application Pool's Advanced Settings.
In IIS 8 and above, the startMode setting is now directly available from the Application Pool's Advanced Settings.
Changing the startMode to AlwaysRunning will automatically restart the Application Pool if it fails.
https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/applicationpools/add/#new-in-iis-75-and-later
Problem with "By default IIS sets all application pools to onDemand" is when you have to update the bits. Then the site will restart and lock the deployment. Better to set the Rapid-fail protection under advanced settings under app pool. Set Failure interval (min) to 1, and Max fail to 5.

which account IIS uses to run asp.net project

Any idea which account IIS uses to run asp.net project. My project or code access file which is in C:\path\path directory. When I test the project in my machine it runs fine (well I am running in built server; Cassini) but when I test the same project in development server where it uses IIS 6.0 ... my code throws a exception "Access to the file C:\path\path is denied".
Not sure how can I solve this? any idea?
Thanks a lot.
Rahul
Find the identity used by the application pool your web application runs under. Here are steps for IIS 6:
Click Start | Run...
Type inetmgr, click OK
In the left-hand pane of IIS Manager, browse to your web application, e.g., My Server | Web Sites | Default Web Site | My Web App
Right-click on the web application, click Properties
In the general tab, note name of the the selected Application pool. Click Cancel
Go back to the left-hand pane of IIS Manager. Browse to My Server | Application Pools | My Application Pool, where My Application Pool is the name you found in step 5, above.
Right-click on My Application Pool, click Properties
Click on the Identity tab. This shows the identity that your web application is running under.
Use the IIS Manager to verify which Application Pool that is running the site you want to investigate.
If you look at the properties for the Application Pool, there is a tab named Identity in which you can determine what user is set to run the process.
You can also use the Task Manager to see which user is running the process named w3wp.exe, which is a process running an instance of IIS (or an Application Pool, in fact).

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path

net project in vs2010 i have a db and table inside the app_data folder, i have created a deployment package and have imported the package into an iis server that is installed on my local mechine.
now i get this error message while trying to preform an insertion.
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed
the connection string is:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\survey.mdf;Integrated Security=True;User Instance=True
when running it inside VS2010 it`s working fine.
how can i solve this probelm ?
Remove the User Instance=True. You don't need RANU instances. Next, make sure the SQL Server Express service account had the proper needed rights on your app_data:
cacls <path\app_data> /E /T /G SQLServerMSSQLUser$<ComputerName>$SQLEXPRESS:F
This article helped solved this issue: http://support.microsoft.com/kb/2002980
Edit From the MSDN article (in case the link disappears):
Resolution for Windows 7 and Windows Server 2008 R2
For all web applications running under IIS 7.5, regardless of their
project type, carry out the following steps:
Run the Internet Information Services (IIS) Manager tool. This tool can be accessed either from the Administrative start menu, or by
typing "inetmgr" in the Windows Start-->Search textbox and selecting
the inetmgr tool.
In the left-hand pane of the IIS Manager tool expand the machine node. Click on the "Application Pools" node so that the application
pools display in the main window of the management tool.
If you are troubleshooting an ASP.NET 2.0/3.0/3.5 application select the "DefaultAppPool" application pool. For ASP.NET v4 select
the "ASP.NET v4.0" application pool.
Right-click on the selected application pool and choose "Advanced Settings"
In the "Advanced Settings" dialog box find the category called "Process Model". The first row in the category will be the "Identity"
row.
Click on the "Identity" row and then click on the small button that shows on the right-hand side of the value cell. The button
displays the text "…"
A dialog box called "Application Pool Identity" will popup. Within that dialog box there are two radio buttons. Make sure the
first radio button titled "Built-in Account" is selected.
In the dropdown box below the radio button choose "Network Service" for the identity.
Click "Ok" to close out the "Application Pool Identity" dialog box.
Click "Ok" to close out the "Advanced Settings" dialog box.
At this point the changes to the application pool identity will have been saved to IIS 7.5's configuration store.
Resolution for Web Application Projects and Websites
For web application projects (WAP) and websites located in a user's
Documents Folder hosted under any version of IIS running as NETWORK
SERVICE, carry out the following steps:
First confirm that IIS has been configured to run as NETWORK SERVICE. This is the default on IIS6 and IIS7. However if you are
running on Windows 7 or Window Server 2008 R2 you will first need to
follow the steps above in "Resolution for Windows 7 and Windows Server
2008 R2" to make IIS application pools run as NETWORK SERVICE.
From a command prompt, type net stop iisadmin /y . This will cause any running ASP.NET WAP applications to shutdown.
Exit out of all running Visual Studio instances.
NETWORK SERVICE must be granted Read permission to the top-level Visual Studio folder located in your user's Documents folder. The
Visual Studio folder will have different names depending on the
version: "Visual Studio 2005", "Visual Studio 2008", or "Visual
Studio 2010".
NETWORK SERVICE must be granted both read and write permissions to your project's top-level project folder. For example if your WAP
project is called "MyCustomWebProject", then the folder
"Documents\Visual Studio 20xx\Projects\MyCustomWebProject" needs to
have read and write access enabled for NETWORK SERVICE. Or, if your
webiste project is called "MyCustomWebProject", then the folder
"Documents\Visual Studio 20xx\Websites\MyCustomWebProject" needs to
have read and write access enabled for NETWORK SERVICE.
NETWORK SERVICE must be granted both read and write permissions to the App_Data folder located within your web project's directory
structure.
The solution with me is
- On IIS ->> Application pool
- Select Default App Pool (it may be different of your website, please choose your pool)
- Advanced setting
- Identity: ApplicationPoolIdentity
- Load user profile: change to true Restart IIS
SOLUTION FOR ENVIROMENT:
Win 7, IIS 7.0, Visual Studio 2010, Database.mdf File
Open the web config and check the conexion string:
Important, make sure the AttachDbFilename is NOT followed by C:\inetpub\<>\App_Data\
<add name="conexion"
connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|Database.mdf;
Integrated Security=True;
User Instance=True" />
In IIS 7.0 Go to ApplicationPools, find the application pool created for the application.
Click Advanced Settings
Go to Identity and open it Select Custom
Account and set the PC or Server user admin account
Then go to the WebSite in IIS 7.0 and click it...
Locate and double click the Authentication icon
Click on Anonymous Authentication and select Edit, then Select Application Pool Identity
Locate the ASP.NET Impersonation and edit, Select on Specify User and then enter the credentials.
Restart IIS:
cmd > iisreset/noforce
or click the reset image button
RUN->INETMGR->
go to Sites select your Site
Then go to Right panel and look for "Basic Settings"
Then Click on "Connect as" Then Select "Specific User" Then Click "Set" Enter Local PC User Name And Password Then Click "OK"
Then Click on "Test Setting" if you see Both options are green then Ok.
Problem Solved
Enjoy...

Resources