Pages

Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

Thursday, November 24, 2011

"Configuration Error: File or assembly name Blarg, or one of it's dependencies, was not found."

This is the equivalent of the ol' "Module not found" error from regsvr32 which didn't tell you what it was looking for that it didn't find either. Most commonly this will be msvcr71d.dll, and it's because you're using a debug version of the assembly.

A FileNotFound exception is being thrown for a DLL and the filename is always different.

Generally this is caused by the constructor of components created on the fly with XmlSerializer, such as SOAP client classes. Make sure the user the process is running under (the identity of the application pool for websites) has read/write permissions to the system temp directory, i.e. "C:\WINDOWS\TEMP\".

"The identity of application pool '%1' is invalid, so the World Wide Web Publishing Service can not create a worker process to serve the application pool. Therefore, the application pool has been disabled."

A user is considered invalid if it isn't a member of IIS_WPG (Internet Information Services Worker Process Group) or it hasn't been granted the right to logon as a service. To check and possibly fix the latter, follow these steps:
  1. Run Local Security Policy applet which is usually under Administrative Tools or you can Start>Run with "secpol.msc".
  2. Expand the Local Policies node and click User Rights Assignment.
  3. Open the "Log on as service" policy either by double-clicking or right-clicking and selecting Properties.
  4. Click "Add User or Group..." and enter the name of the user for the app pool's identity.
  5. Restart the machine. The security policy is only read on boot.
If this doesn't solve the problem, or for more detailed information you can check the Security Event Log for the user you specified as the identity around the time the problem occurred. There will usually be three entries under the categories: Logon/Logoff, Privilege Use, and then another Logon/Logoff. You can look at these to see what privileges that user was granted when it logged in, what came up when privileges were queried, etc. It's fairly hefty material.

"A failure was encountered while launching the process serving application pool 'blarg'. The application pool has been disabled."

The most likely cause is the identity specified could not be used for the application pool. In this case there should be a warning that occurred just before this error in the Event Log which is detailed below.
Confused? Got questions? Comments? Make use of your broadband and send me an email. I'll get back to you as soon as possible. Please be as specific as possible in your inquiry. Thanks!

A Windows Authentication dialog box is popping up when trying to view ASPX; it won't accept any credentials and eventually will display a "Not Authorized" error page.

ASP.NET is getting an Access Denied error when trying to use "C:\Windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\". The identity used by the application pool does not have read/write permissions to that directory.

"Service Unavailable"

Check the System Event Log (run "eventvwr /s"). You should see and Error and maybe a Warning as well from the W3SVC Source at the time you were trying to view the web site/service. One of these will give you a slightly more specific problem which should be resolved in this document.

HTTP 404: The page cannot be found. (ASMX or ASPX)

IIS 6+ is setup to return a 404 on executable types that are unrecognized or prohibited. This is the case with both ASP.NET 1.1 and 2.0.
  1. Open the "Internet Information Services (IIS) Manager" under "Administrative Tools".
  2. Navigate to the "Web Service Extensions" node.
  3. Select "ASP.NET v1.1.4322" or "ASP.NET v2.0.50727" in the right pane.
  4. Click "Allow".
If you don't see the expected version of ASP.NET listed under "Web Service Extensions", it's typically because IIS was installed after .NET. You can run the aspnet_regiis.exe utility to remedy this:
  1. Get to a command prompt, e.g. Start>Run "cmd".
  2. Enter "CD /D C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322" or "CD /D C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" depending on which version of ASP.NET.
  3. Enter "aspnet_regiis.exe -i".
  4. Wait for the finished message; "Start installing ASP.NET (1.1.4322.0)" or "Start installing ASP.NET (2.0.50727.0)" depending on which version of ASP.NET.
  5. Follow the previous set of steps to enabled ASP.NET in Web Service Extensions.

Installing and Running node.js applications within IIS on Windows - Are you mad?

Some folks on our team have been working on making node.js work awesomely on Windows. There's a few questions you might have.

First, what's node.js?

If you're not familiar with node.js, it's a new web programming toolkit that everyone's talking about. It's the one that makes you feel not hip if you don't know what it is. Like Ruby on Rails was a few years back. Folks called it "Node" and it's basically server-side JavaScript. The idea is that if you are doing a bunch of JavaScript on the client and you do JavaScript all day, why not do some JavaScript on the server also. One less thing to learn, I suppose.
If you are an ASP.NET programmer, you can think of node.js as being like an IHttpHandler written in JavaScript. For now, it's pretty low-level. It's NOT an HttpHandler, but I'm using an analogy here, OK? Here's a lovely article by Brett McLaughlin that goes into more detail about Node.js and what it is. His subtitle is "Node isn't always the solution, but it does solve some important problems" and that's just exactly it.

Why would I want node.js to run on Windows and IIS?

Tomasz Janczuk is working on the iisnode project lately. You might think that Windows and node don't belong together. "That's just wrong! What are they thinking? I thought IIS was all about .NET?" Well, you may recall I spoke at CodeMash a few years back on IIS7 and PHP and did a screencast showing how IIS7, PHP and FastCGI could push many thousands of requests a second. The IIS folks, the Windows folks, the Azure folks, want to make sure everything runs well on Windows. Remember, we sell Windows, so it's good if it does many things well. ;)
Why bother getting node to run on IIS? Tomasz says it best:
Some of the advantages of hosting node.js applications in IIS using the iisnode module as opposed to self-hosting node.exe processes include:
  • Process management. The iisnode module takes care of lifetime management of node.exe processes making it simple to improve overall reliability. You don’t have to implement infrastructure to start, stop, and monitor the processes.
  • Scalability on multi-core servers. Since node.exe is a single threaded process, it only scales to one CPU core. The iisnode module allows creation of multiple node.exe processes per application and load balances the HTTP traffic between them, therefore enabling full utilization of a server’s CPU capacity without requiring additional infrastructure code from an application developer.
  • Auto-update. The iisnode module ensures that whenever the node.js application is updated (i.e. the script file has changed), the node.exe processes are recycled. Ongoing requests are allowed to gracefully finish execution using the old version of the application, while all new requests are dispatched to the new version of the app.
  • Access to logs over HTTP. The iisnode module provides access the output of the node.exe process (e.g. generated by console.log calls) via HTTP. This facility is key in helping you debug node.js applications deployed to remote servers.
  • Side by side with other content types. The iisnode module integrates with IIS in a way that allows a single web site to contain a variety of content types. For example, a single site can contain a node.js application, static HTML and JavaScript files, PHP applications, and ASP.NET applications. This enables choosing the best tools for the job at hand as well progressive migration of existing applications.
  • Minimal changes to node.js application code. The iisnode module enables hosting of existing HTTP node.js applications with very minimal changes. Typically all that is required is to change the listed address of the HTTP server to one provided by the iisnode module via the process.env.PORT environment variable.
  • Integrated management experience. The issnode module is fully integrated with IIS configuration system and uses the same tools and mechanism as other IIS components for configuration and maintenance.
  • In addition to benefits specific to the iisnode module, hosting node.js applications in IIS allows the developer to benefit from a range of IIS features, among them:
    • port sharing (hosting multiple HTTP applications over port 80)
    • security (HTTPS, authentication and authorization)
    • URL rewriting
    • compression
    • caching
    • logging
These are all compelling, but the most interesting bit here, in my opinion, is integration. The iisnode module is a proper IIS module, just like ASP.NET and PHP. This means you can have a single website that has multiple kinds of content. Restated from above:
For example, a single site can contain a node.js application, static HTML and JavaScript files, PHP applications, and ASP.NET applications.
Sometimes folks freak out when I say you can have an ASP.NET WebForms app and a ASP.NET MVC app in the same AppPool as a "hybrid." Frankly, Dear Reader, people don't even realize the power and flexibility of IIS. When you plug in something new like node but run it the way you run other things it inherits all the coolness of the outer container, in this case, IIS.

Fine, you got me, how do I run node.js on Windows?

I'm assuming you are running IIS7.
  • Go download node.exe, and put it in c:\node
  • Go download a build of iisnode.
  • Unzip iisnode's zip into \inetpub\iisnode
    • (that was my idea, not sure if it's the best place)
  • From an Administrator Command Line, run install.bat.
The install.bat will:
  • unregister existing "iisnode" global module from your installation of IIS if such registration exists
  • register iisnode as a native module with your installation of IIS
  • install configuration schema for the "iisnode" module
  • remove existing "iisnode" section from system.webServer section group in applicationHost.config
  • add the "iisnode" section within the system.webServer section group in applicationHost.config
  • delete the iisnode web application if it exists
  • add a new site iisnode to IIS
No warranties! Be careful, you're living on the edge. Remember, you're reading this stuff on some random dude's blog.
WARNING: I couldn't figure out the right permissions for the AppPool and the File System so I wimped out and gave my local AppPool "SYSTEM" permissions. This is awful and totally my fault. I filed an issue on the iisnode GitHub and I'll fix it and update this post when I hear back.
I made a new AppPool just for node, gave it SYSTEM access, then assigned the Node Site to this new AppPool. Your site should look like:
Node Site in IIS7
And if you click on Modules for this Site in IIS7 you should see iisnode as a native module:
Hey, it's iisnode as a native module, just like I said. Crazy.
At this point, you should be able to hit http://localhost/node/helloworld/hello.js and get back:
Hello, world! [helloworld sample]
The contents of which are simply:
var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT);  
Lovely.

Fooling around with WCAT (Web Capacity Analysis Tool) and node.

Disclaimer: To be clear, this is so very fooling around. This is just to show that it works and it can do the basics really fast. I'm not doing a benchmark nor am I saying "this works better than this other thing." Remember, they just got started recently porting node itself to Windows, and Tomasz and friends are just beginning their work. So, don't overreach. That said, the preliminary work they are doing is really impressive.
I couldn't help myself. I mean, it's one thing to install a helloworld of some new thing, run it once and go "OK, that runs." It's another to pound it until it says "Uncle." After I got the hello world stuff working, I wanted to do some poor man's stress testing to see what the players involved did.
First, I installed WCAT, a free Web Capacity Analysis Tool from the IIS team.
  1. WCAT 6.3 x86
  2. WCAT 6.3 x64
Warning. This is a command-line only tool and it's really persnickety when you run it. It's confusing and it took me a minute to setup.  Here's the steps I took after installing. This is all from an Administrator Command Prompt. Note also that I'm doing this all on one machine, which is cheesy, but remember, it is a GOM.
  1. cscript //H:Cscript
  2. wcat.wsf –terminate –update –clients localhost
  3. Then I made a folder I called \nodetests and I put these three files in it:
wcat.bat
pushd C:\Users\Scott\Desktop\nodetests
"c:\program files\wcat\wcat.wsf" -terminate -run -clients localhost -f settings.ubr -t nodescenario.ubr -s localhost -singleip  -o C:\Users\Scott\Desktop\nodetests
pause
nodescenario.ubr (or call it whatever you want)
This is so basic. It just beats on the four sample applications for a while.
scenario
{
  name    = "node_fun";

    warmup      = 30;
    duration    = 90;
    cooldown    = 30;

    default  
    {
        setheader
        {
            name    = "Connection";
            value   = "keep-alive";
        }
        setheader
        {
            name    = "Host";
            value   = server();
        }
        version     = HTTP11;
        statuscode  = 200;
        close       = ka;
    }
    
    transaction
    {
        id = "foo";
        weight = 1000;
        request
        {
            url = "/node/logging/hello.js";
        }
    }
    transaction
    {
        id = "bar";
        weight = 2000;
        request
        {
            url = "/node/helloworld/hello.js";
        }
    }
    transaction
    {
        id = "baz";
        weight = 2000;
        request
        {
            url = "/node/defaultdocument/";
        }
    }    
    transaction
    {
        id = "bat";
        weight = 2000;
        request
        {
            url = "/node/configuration/hello.js";
        }
    }    
}
settings.ubr
I just copied in the one from samples and uncommented out and changed (and tweaked during testing) these lines:
server         = "hexpower7";
clients        = 1;
virtualclients = 8;
Now, run the Test
Next, I ran wcat.bat as an Administrator...you can see all the little node.exe's firing up. I've got a
(Remember they are running as SYSTEM because I was unable to figure out the right permissions. That's my bad, no one else's. I'll figure it out one day.)
Lots of little node processes
Here's the WCAT tool's console output...I'm able to consistently do 10,000 hello worlds a second and ended up with just under a million normal requests and responses in 90 seconds. That's a lot of hello worlds.
Remember Hanselman's Rule of Scale.
"If you do nothing, you can scale infinitely." - Me
Of course, this is all local on a fast machine. This is just hello world (with some logging) so it's not testing node much, nor IIS much, but rather the collaboration between the whole system, IIS, iisnode, and node itself.
Pushing a million transactions in 90 seconds
There's a lot of things I could configure on both sites, number of clients, virtual clients, as well as iisnode-specific settings (which are, nicely enough, managed in a web.config:
<configuration>
  <system.webServer>
    <handlers>
      <add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
    </handlers>
    <iisnode      
      nodeProcessCommandLine="%systemdrive%\node\node.exe"
      maxProcessCountPerApplication="4"
      maxConcurrentRequestsPerProcess="1024"
      maxPendingRequestsPerApplication="1024"
      maxNamedPipeConnectionRetry="3"
      namedPipeConnectionRetryDelay="2000"      
      asyncCompletionThreadCount="4"
      initialRequestBufferSize="4096"
      maxRequestBufferSize="65536"
      uncFileChangesPollingInterval="5000"
      gracefulShutdownTimeout="60000"
      loggingEnabled="true"
      logDirectoryNameSuffix="logs"
      maxLogFileSizeInKB="128"
      appendToExistingLog="false"
     />
   </system.webServer>
</configuration>
This is pretty cool stuff. I like that the team I work with is excited to make things work well on IIS and I'm stoked that I can mess around with node now without firing up VMs. I'll report back as I learn more!

Deploying LightSwitch Applications

Hopefully this is because LightSwitch is still in beta (as of this writing on 5/31/11) but from our research and testing, it seems that the documentation in the following article is correct:
"Publishing a 3-tier application requires that you have administrative access to a server that is running IIS and is preconfigured for LightSwitch, and also that you have administrative access to a computer that is running SQL Server." (http://msdn.microsoft.com/en-us/library/ff872288.aspx)
That's a tremendous failure (if not addressed) of the product. It means that publishing a LightSwitch application to a shared host is not an option (though I've heard of possible manual configuration workarounds). It also means that in a corporate world you either need a trusted deployment team with elevated permissions, or you need to give your developers or QA people administrative access to servers (generally a no-no).
LightSwitch has a Publish Application Wizard that seems to leverage Web Deploy so hopefully the LightSwitch team will address this publishing challenge so that any host supporting standard Web Deploy services can accept and support LightSwitch applications.

IIS7 Application Pool Idle Time-out Settings

Whether you host in-house or with a managed Windows hosting provider, if you self-administer a web server it is good to know that by default IIS7 sets application pools to "time-out" after 20 minutes of inactivity. So if you don't have a visitor to your site within 20 minutes the application pool will shut down - freeing up those system resources. Then the next time a request comes into the site IIS7 will automatically restart the application pool and serve up the requested pages.
This is a great way to preserve resources since every running application pool does place a certain amount of overhead on the system. But, it also means that the first request - the one that causes the application pool to restart - is very slow. It is slow because the process literally needs to start, then load the required assemblies (like .NET) then load the requested pages. Depending on the size and complexity of your application, this might just be a couple of seconds or it might take 30+ seconds (during which time a user would likely give up and move on to a different site).
If you want to extend the length of the time-out setting, just change it from the default of 20 to however many minutes you want. You can also adjust the setting to 0 (zero) which effectively disables the timeout so that the application pool will never shut down due to being idle.
To make this change, open Server Manager; Expand the Roles node; Expand the Web Server (IIS) node. Then click on the Web Server (IIS) node; Expand the node with your local server name; and click on the Application Pools icon. You'll then see a list of the application pools that are defined on your server. In the right-hand pane you'll see an option for Advanced Settings - click that.


Once you see the Advanced Settings dialog box just look for the Idle Time-out (minutes) property; click where the default "20" is, and change it to whatever value you prefer.


This is just one of many settings that can impact the performance, uptime, and functioning of your web site. If you don't have the time or interest in learning and maintaining the various settings for a secure high-performing web server, you might want to consider a fully managed windows hosting solution and let a trained and experienced administrator take care of the work for you.

How to set content expiration for your IIS7 site

Do you want to assure that client browsers will always download the latest copy of your page(s) rather than potentially pulling an outdated page from their local cache? You can enable and manage content expiration in IIS7 to control this at the server-side. Below is a walk-through of enabling this using the IIS7 Remote Management Services.
You access the setting from the IIS management console: Select the HTTP Response Headers module:

Then on the right-hand side of the console click the Add Common Headers link:

The dialog box that shows next has an Expire Web Content checkbox:

From there you can select to have the content expire immediately if you don't want the browser to cache anything at all; or to expire after a certain period of time (certain number of minutes, hours, days, etc.); or set it to expire on a certain specific date:

OrcsWeb's managed hosting plans and Cytanium's discount shared hosting plans all support IIS7 Remote Management Services. If you aren't sure if your host supports this, just ask them. If they don't you can still manage these settings through the web.config file.
Here's a quick sample for turning off client caching for your .Net site:
<configuration>
   <system.webServer>
      <staticContent>
         <clientCache cacheControlMode="DisableCache" />
      </staticContent>
   </system.webServer>
</configuration>
Note that some hosts may have this feature locked down. If you encounter any issues just touch base with the host to confirm they support this.
Happy hosting!

IIS 8 on Windows 8 Technical Preview

oday Microsoft released the technical preview bits of its latest operating system "Windows 8" ... Though windows 8 is being show cased as the next generation tablet OS ... I had to install IIS as the 1st thing I did after "windows 8" install.

Short Story: There is no real difference in the install experience from that of IIS 7...

Long Story: You will still need to install IIS 8 from "Turn Windows Features on\off", however the way you reach there is slightly different now...

  • Once you are on the Home Screen (The new Metro UI coolness that you see everywhere) click on Control Panel
  • This will take you to a new control panel page (which looks simple and cool by the way) ... Once at this page go to the last option that says "More Settings"
  • This will get you to the familiar Windows 7 control panel settings page from wherein you will go to Programs --> Turn windows features on\off --> Internet Information Services --> Select --> leave Default and say ok
  • That's it... once the result displayed is success ... go to IE and browse localhost ... 

The first noticeable difference you will find after you install IIS on Windows 8 TP is the localhost start page ... For all of you who haven't check it out yet ... here it is ...


Will be posting a lot more once I am through configuring "IIS 8" ...

Note: Check out how HTML 5, PHP and ASP.Net are included in number "8" ... Need I say more about Microsoft's commitment towards PHP and HTML 5 ??

Next Steps ... Going to Run PHP :-)

How to use Managed Code (C#) to create an FTP Home Directory Provider that is based on the Remote Client IP Address

I recently had an interesting scenario that was presented to me by a customer: they had a business requirement where they needed to give the same username and password to a group of people, but they didn't want any two people to be able to see anyone else's files. This seemed like an unusual business requirement to me; the whole point of keeping users separate is one of the reasons why we added user isolation to the FTP service. With that in mind, my first suggestion was - of course - to rethink their business requirement, assign different usernames and passwords to everyone, and use FTP user isolation. But that wasn't going to work for them; their business requirement for giving out the same username and password could not be avoided. So I...

URL Rewrite city.domain.com to domain.com/city

An IIS 7.x URL Rewrite question that comes up often is how to redirect something.domain.com to domain.com/city. Here’s an example URL Rewrite rule to accomplish that: < rule name ="CName to URL" stopProcessing ="true" > <...