EzDevInfo.com

iis-8.5 interview questions

Top iis-8.5 frequently asked interview questions

How can I enable "URL Rewrite" Module in IIS 8.5 in Server 2012?

I have windows server 2012 and I have installed the IIS 8.5 but I could not see the URL rewrite module. How can I enable or install?


Source: (StackOverflow)

WCF on IIS8; *.svc handler mapping doesn't work

I'm trying to get a wcf service running in IIS8 on 2012 build 8400.

When installing the web role the wcf stuff (under 3.51) wasn't to be found like in 2008.

When installed the svc handler mapping was missing, so i did a:

%windir%\Microsoft.NET\Framework\v3.0\WindowsCommunication Foundation\ServiceModelReg.exe –i

Now the handler mapping is there, but I still get:

The resource you are looking for does not have a handler associated with it.

(I removed the static file handler.)

The site is using the classic pipeline in order to use impersonation.


Source: (StackOverflow)

Advertisements

HTTP to HTTPS Redirect - IIS 8.5 not working properly

I've read a number of posts here on SO as well as on the 'net (IIS blogs, etc.). I'm trying to force all connections going from domain.com to www.domain.com and at the same time forcing the request from HTTP to HTTPS.

I'm using this set of rules and rewrites but the only thing happening is that it's redirecting fine but not redirecting to SSL.

<!-- Redirect to HTTPS -->
<rewrite>
    <rules>
        <rule name="Redirect to www" stopProcessing="true">
            <match url="(.*)" />
            <conditions trackAllCaptures="false">
                <add input="{HTTP_HOST}" matchType="Pattern" pattern="^mydomain.com$" ignoreCase="true" negate="false" />
            </conditions>
            <action type="Redirect" url="{MapProtocol:{HTTPS}}://www.mydomain.com/{R:1}" />
        </rule>
    </rules>
    <rewriteMaps>
        <rewriteMap name="MapProtocol" defaultValue="http">
          <add key="on" value="https" />
          <add key="off" value="http" />
        </rewriteMap>
    </rewriteMaps>
</rewrite>

What am I doing wrong?

Main blog reference: http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action and this SO post - web.config redirect non-www to www


Source: (StackOverflow)

How do I create an application pool with specific user in IIS 8.5 using PowerShell?

The shortened code below works, but it winds up using the ApplicationPool identity, not the specific ones that I specify in the array.

Declarations:

#App pool array positions
$Name = 0
$User = 1
$Pwdx = 2

#Application array positions
$SiteNm = 0
$PhyPath = 1
$PoolNm = 2

#App Pool Settings
$Port="80"
$HostName="*"
$Environment="local"
$Runtime="v4.0"
$Pipeline="0" #Integrated
$Identity="3" #SpecificUser

#Define the App Pools
$Pools = @(3)*2
$Pools[0] = "SomeAppPool","FooBar\SomeUser","S0meUs3rP4ssw0RD"
$Pools[1] = "AnotherAppPool","FooBar\AnotherUser","An0th3rUs3rP4ssw0RD"

Execute Code:

Import-Module WebAdministration

#navigate to the app pools root
cd IIS:\AppPools\   

foreach($p in $Pools)
{ 
    $AppPoolName = $p[$Name]
    $AppPoolUser = $p[$User]
    $AppPoolPwd = $p[$Pwdx]

    $appPool = New-Item $AppPoolName
    $appPool | Set-ItemProperty -Name managedRuntimeVersion -Value $Runtime
    $appPool | Set-ItemProperty -Name managedPipelineMode -Value $Pipeline
    $appPool | Set-ItemProperty -Name processModel.identityType -Value $Identity
    $appPool | Set-ItemProperty -Name processModel.username -Value $AppPoolUser
    $appPool | Set-ItemProperty -Name processModel.password -Value $AppPoolPwd

    Write-Host "$AppPoolName Application Pool Created..."
}

Source: (StackOverflow)

ithit-ajax-file-browser active directory WebDav auto-login

I'm using Active Directory in Windows Server2012 R2 and IIS 8.5 to create a WebDav for each user and it can be accessed via the user-name and user-password. One folder per user. This works perfectly using WebDav clients. I have also a web browser using ithit-ajax-file-browser.

My problem is, when i set parameters to the web-part the server shows up an authentification pop-up before logging me automatically.

I'im using

    var settings = {
                    BasePath: '/davbrowser/',                      
                    Id: 'AjaxFileBrowserContainer',     
                    Url: webDavServerPath,              
                    Style: 'height: 100%; width: 100%', 
                    MsOfficeTemplatesPath: '/templates/', 
                    SelectedFolder: webDavServerPath,   
                    ThemeName: 'windows_8',             
                    IconsSize: 16                       
                    //Platform: 'mobile'                
                };
var ajaxFileBrowser = new ITHit.WebDAV.Client.AjaxFileBrowser.Controller(settings);
ajaxFileBrowser.GetSession().SetCredentials('username', 'password');
ajaxFileBrowser.SetSelectedFolder('/username');

`

The auto-login works but the login pop-up still appears. Are there any solution to delete it? I'm using basic authentification


Source: (StackOverflow)

HTTP Module intercept requests and breaks custom errors configuration

I have an ASP.NET MVC 5 web application which runs locally on IIS 8.5 and after deployment, on Azure Websites - on both cases, the behavior that will be later described is the same.

I configured in the web.config the following custom errors page management (it covers all my cases of custom errors and it has been tested and it's working great):

<system.webServer>
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <clear />
    <error statusCode="400" responseMode="ExecuteURL" path="/App/Error"/>
    <error statusCode="403" responseMode="ExecuteURL" path="/App/Error/Forbidden" />
    <error statusCode="404" responseMode="ExecuteURL" path="/App/Error/NotFound" />
    <error statusCode="500" responseMode="ExecuteURL" path="/App/Error" />
  </httpErrors>
</system.webServer>

Also, I have an HTTP Module configured in the same web.config like this:

<system.webServer>
<modules>
  <add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" />
 </modules>
</system.webServer>

The issue that I have is like this: if I'm making a request to a strange URL like .../c<, the application executes the 500 custom error path as instructed in the web.config file. But, if I'm making a request to a stranger URL (to simulate an html tag) like .../<c, though the resulted error is 500, the custom error is not executed anymore, because accordingly to the detailed error, the HTTP Module intercept the call and "decides" to just show a YSOD...

The message that I get is:

A potentially dangerous Request.RawUrl value was detected from the client (="/App/

And is easy to see that this is caused by the webmodule because of the stacktrace:

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.RawUrl value was detected from the client (="/App/d__10.MoveNext() +201 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84 System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +98 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +434 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

If I'm commenting out the Image Processor Module from the web.config, everything runs as expected.

Why in this case, the custom error path doesn't get executed?

Thank you for your time and answers.


Source: (StackOverflow)

What would cause this property to occasionally throw a NullReferenceException?

I have an asp.net/C# class that resizes images for caching on the server as files, however the portion of the code that determines which encoder to use seems to occasionally throw a NullReferenceException.

Here is the code which initializes and passes back the encoders:

public static class ImageUtilities{    
    private static Dictionary<string, ImageCodecInfo> encoders = null;

    public static Dictionary<string, ImageCodecInfo> Encoders{
        get{
            if (encoders == null){
                encoders = new Dictionary<string, ImageCodecInfo>();
            }

            //if there are no codecs, try loading them
            if (encoders.Count == 0){
                foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders()){
                    encoders.Add(codec.MimeType.ToLower(), codec);
                }
            }

            return encoders;
        }
    }
    ...

This is the specific line the exception is being thrown on:

encoders.Add(codec.MimeType.ToLower(), codec);

This is the error text:

Object reference not set to an instance of an object.
    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)

This is the only place where the Encoders property is called (and subsequently is the line below that one in the stack trace):

if (Encoders.ContainsKey(lookupKey)){
    foundCodec = Encoders[lookupKey];
}

Even if lookupKey were null, shouldn't the lookup just return null rather than throwing an exception?


Source: (StackOverflow)

Why can't I see a virtual directory created in Visual Studio 2013 for Local IIS in IIS Manager?

I'm trying to debug a problem where my local IIS has mysteriously decided to not recognize my virtual directory.

In my MVC 4 project, my web server is set to "Local IIS" and my project URL is set to http://localhost/MySite. When I hit the Create Virtual Directory button, I get the message "The virtual directory was created successfully."

But when I go IIS Manager and click on Default Web Site | MySite | View virtual directories no virtual directories are listed. This is also the case for the web site where the virtual directory does work.

Why can't I see a virtual directory created in Visual Studio 2013 for Local IIS in IIS Manager?

Where can I see the virtual directories created by VS?


Source: (StackOverflow)

IIS AppPool to SQL Server permissions (adding NT AUTHORITY\IUSR)

I've got a new server build running Windows Server 2012 R2, IIS 8.5 (inc. ClassicASP feature) and SQL Server 2014 Express. I want to use Application Pool Identity to connect to the database. The database is set to "Windows Authentication Mode".

My Application Pool Identity is called activbase.net. I've set up a Security Login in SQL Server called IIS AppPool\activbase.net and user mapped it my database with db_datareader and db_datawriter access.

However when I try to access the database from the website, I get:

Cannot open database "ActivbaseLive" requested by the login. The login failed.

I thought this was enough to get the connection working. The Application Log (Event Viewer) shows:

Login failed for user 'NT AUTHORITY\IUSR'. Reason: Failed to open the explicitly specified database 'ActivbaseLive'. [CLIENT: ]

So I have added NT AUTHORITY\IUSR likewise to the SQL Server>Security>Logins and Databases>[ActivbaseLive]>Security>Users and this fixes the problem.

My questions are as follows:

  1. Should I be needing to add NT AUTHORITY\IUSR login/user in addition to IIS AppPool\activbase.net login/user to my SQL Server Instance and database?
  2. Is there a security issue with doing this? (NOTE: this will be a production environment)

Thanks, Chris


Source: (StackOverflow)

IIS changes the physical path to application it self

I have set two websites in my IIS 8.5. I have one for production version and one for development (need this for the team work purposes). The structure is simple. Website is simple static page using BackboneJS and API calls to get all the data. All virtual paths and applications were set at the beginning manually by my self. For some reason some API calls didn't worked in dev site. I found out the physical path to the API project has changed. Do you have any idea, where can be the problem? Actually some of my collegues face this issue too.

Only think that cames to my mind is that when bdebugging the API, I use "Attach to process" in Visual Studio, where I connect to the correct IIS process - w3wp.exe with user name IIS APPPOOL\Dev or IIS APPPOOL\Prod according to the site I'm debugging.

Nevertheless I don't think the path should change itself. Where can be the problem? Does anyone have any idea how to prevent this strange behaviour?


Source: (StackOverflow)

IIS 8.5 forces incorrect Content-Length header

We have a application that generates PDF files dynamically and forces a download of a the file. This code was working without issue on a Windows Server 2008. From what I can tell it appears that IIS is forcing the Content-Length to a value of 749 while it should be 83233. I have tried setting that value in the application code and IIS ignores it completely.

  • Microsoft's URL Rewrite is installed but there are no entries for this site
  • I have disabled compression of static and dynamic content
  • Via the application code I am trying to set the Content-Length header and also setting the X-Content-Length header to the same value. This is how I am sure that the value is being overwritten by IIS
  • When I hit the same URL via the built in web server of ColdFusion the download works without issue. This is why I know this is a issue with IIS or the connector between IIS and ColdFusion.

Here is the response headers from the server

Response Headers
-------------------------------------------------------------
Connection: close
Content-Length: 749
Content-Type    : application/pdf;charset=UTF-8
Date: Thu, 13 Nov 2014 03:36:03 GMT
Server: Microsoft-IIS/8.5
X-Content-Disposition: attachment;filename=LasVegas.pdf
X-Content-Length    :83233
X-Powered-By    :ASP.NET

Here is the code

<cfcontent reset="true"/>
<cfset variables.temporaryFilePath = "C:\inetpub\wwwroot\LasVegas.pdf">
<cfheader name="Content-Length" value="#getFileInfo(variables.temporaryFilePath).size#"/>
<cfheader name="X-Content-Length" value="#getFileInfo(variables.temporaryFilePath).size#"/>
<cfheader name="X-Content-Disposition" value="attachment;filename=LasVegas.pdf">
<cfcontent type="application/pdf" file="#variables.temporaryFilePath#" deleteFile="no">

Source: (StackOverflow)

IIS 8.5 Not honoring Web API [EnableCors] attribute. Not setting Access-Control-Allow-Origin Header

Rundown

So I've continued tinkering with this. This is a new Windows Server with IIS 8.5. I've never had any problems getting CORS to "just work" in IIS so I've never really needed to care about the fiddly bits in the server config. The immediate fix was the shotgun approach; I enabled CORS server-wide with the following modification to applicationhost.config

   <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
   </customHeaders>

but removing this customHeader and setting [EnableCors(origins: "*",headers: "*", methods: "*")] inside my controllers does not cause the server to send back Access-Control-Allow-Origin response headers (yes, I made sure to call config.EnableCors() in my HttpConfiguration.

An additional complication is that using this method, I have to allow all origins because I need several origins to be able to access this server. Browser implementations do not permit multiple origins to be sent back from the server in this header. I could always write my own EnableCors logic within my application, but would rather understand and fix the server config to stay on the res.


Original Question

So I'm running into a bit of an issue trying to get a Web Application deployed to IIS 8.5 on a fresh Windows Server 2012 R2 straight from our server provisioning team. My application is a Web API with Cors Enabled, (currently allowing all origins) but the server is not returning an Access-Control-Allow-Origin header to calling clients. I've never had an issue with Web API Cors "just working."

I found this resource, but confirmed that the OPTIONSVerbHandler had already been removed within my application's web.config.

I tried to add a customHeader to IIS, but whenever I did that, the server started returning 500s.

Is there anything that I can do to force IIS 8.5 to send Access-Control-Allow-Origin headers from ASP.NET?


Edit1

So I apparently installed the ASP.NET Cross Origin Resource Sharing NuGet package into my solution rather than the ASP.NET Web API 2.2 Cross Origin Resource Sharing NuGet package. I swapped these out and I have limited (but still unexpected) CORS functionality. I'll describe the weirdness I'm experiencing now.

So before I realized I had the wrong NuGet package, I had gone into applicationHost.config and added

<customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>

in an attempt to get the server to push the header back manually. Without the NuGet update, this did not set the header on preflight responses but at this point I'm not quite sure if that was due to me forgetting an iisreset;I was trying to move fast.

At any rate, when I added the Web API 2.2 Cors NuGet package, my server responses started emitting an Access-Control-Allow-Origin header with wildcard origins rather than the ones that I had set in my EnableCors attributes inside my Web API routes. So with that value, I knew that it was the configured customHeader rather than the EnableCorsAttribute that is now controlling the value.

(Here's where the weirdness comes in) So I would actually prefer to be able to directly control the CORS whitelist directly at the server level, so I went ahead and set the customHeader to

<customHeaders>
   <add name="Access-Control-Allow-Origin" value="http://segment.mydomain.com" />
</customHeaders>

where http://segment.mydomain.com also matches one of the allowed origins inside my API routes.

I now get the proper Access-Control-Allow-Origin sent back from IIS in the PreFlight request, but the subsequent POST returns a 500. If I remove the EnableCors attribute from my Api Route, the POST succeeds (confirmed by directly querying the database that persists the posted data)

...wt*?


Edit2

So that hopeful approach (statically defined origins inside a customHeader in IIS rather than allowing developers to list their origins directly inside controllers) won't actually work. I need to whitelist multiple origins and Chrome's implementation only allows one origin to be set in the ACAO header. It also will not allow wildcard segments in origins, so...that sucks.


Source: (StackOverflow)

Auto configuring IIS websites / app pools using PowerShell or other scripts

We have a need in our project to automate the process of creating AppPools and Websites in IIS . We would like to write some batch script to get this done. From my research I found that PowerShell has commands that can be used. However when I tried to run IIS module commands in PowerShell on Windows Server 2012 , it does not recognize the commands. Is it correct that this feature was only available for Windows 7 / IIS 7 ? Is it also available now on Windows 2012 R2 / IIS 8. If so where can I find proper documentation and help ?


Source: (StackOverflow)

Deploy ASP.NET RC1 WebApp in IIS 8.5

I am trying to deploy an ASP.NET 5 WebApp in a Windows Server 2012 R2 that has IIS 8.5 installed.

The source code that I have here is a new ASP.NET Web Application. If I build it and run it in Visual Studio 2015, then works fine.

Now... I want to use the publish wizard to deploy it in ISS 8.5 so what I do is...

  1. Right click on the project name (WebApplication5)
  2. I created a custom profile (I named as localhost)
  3. I add the target location. C:\inetpub\wwwroot
  4. I configure the Settings
    • Configuration: Release
    • Target DNX Version: dnx-clr-win-x64.1.0.0.rc1-update1
  5. Then I publish the web app.

After that, I have the following folder structure in my C:\inetpub\wwwroot

C:\inetpub\wwwroot
     - approot
         - packages
         - runtime
         - src
         - ... bunch of files
     - logs
     - wwwroot
         - css
         - images
         - js
         - lib
         - some files including web.config

Now I edited the permissions of the C:\inetput\wwwroot to include IIS_IUSRS and IUSR (I gave them full access for now to discard permission issues)

Finally, I went to ISS manager to Default Web Site -> Right Click -> Manage Website -> Advanced Settings -> and under physical path I added C:\inetpub\wwwroot\wwwroot

I restarted the IIS Server and when I try to browser to the default site I got the following message...

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid. Detailed Error Information:

Module IIS Web Core

Notification Unknown

Handler Not yet determined

Error Code 0x8007000d

Config Error

Config File \?\C:\inetpub\wwwroot\wwwroot\web.config

And finally... this is the content of the web.config file...

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

What am I missing? That used to be super easy on previous versions of ASP.NET but I can't configure this properly now.

Any pointers? Thanks!


Source: (StackOverflow)

PHP 5.5 and MSSQL driver: Installing ODBC Driver 11 in Windows Server 2012 R2

I have a Windows Server 2012 R2 with IIS 8.5, and another server with MSSQL 2012. I must install PHP in IIS and connect to MSSQL, and I don't have Internet available for Web PI.

I managed to install PHP 5.5 and I'm able to run phpinfo(), and I also assured that php.ini is being loaded from C:\php\php.ini.

I was also able to load sqlsrv driver, it reports in example sqlsrv.ClientBufferMaxKBSize 10240 10240.

But when I execute a php file that connects to DB, I get a message

This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712

I went to that site and it says

Supported operating systems for version 3.1 of the driver include Windows Server 2012 R2`.

It says

Version 3.1 requires Microsoft ODBC Driver 11 (or higher) for SQL Serverand points tohttp://www.microsoft.com/en-us/download/details.aspx?id=36434`.

In that page, in System Requirements, WinServer 2012 R2 is not listed. When I try to install msodbcsql.msi I get message

Installation of this product failed because it is not supported on this operation system. For information on supported configurations, see the product documentation.`

Well I'm now stuck. I need PHP in WinServer 2012 R2 and IIS 8.5 connecting to MSSQL 2012. But its driver requires ODBC 11, which seems to not support latest WinServer.

Is there any hope, or will I need to wait for Microsoft to support its own OS in its own drivers?


Source: (StackOverflow)