LoginSignup
45
44

More than 5 years have passed since last update.

IIS Express を外部公開する

Last updated at Posted at 2016-06-27

背景

Mac上の仮想環境上のWindows上でAPS.Netアプリケーションを開発しているときに

  1. ゲストOS(Windows)上のIIS Expressでアプリケーションを実行
  2. ホストOS(MacOS)上のブラウザで動作を確認

したいことがあります。
クライアント側のJavaScript部分をReactなどで実装している場合、Reactの開発にはOSの縛りがありません。
ホストOS上の方がファイルの編集・実行が速いので、Reactアプリケーションの

  1. 編集
  2. ビルド

をホストOS上でしたいです。

このために、IIS ExpressをLAN上に公開したいです。

環境

  • Windows 10 Pro
  • Visual Studio Community 2015 update2
  • IIS 10.0 Express

手順

解決すべき課題

  1. IIS Expressはデフォルトでlocalhost:xxxxにバインドされる。ドメイン名やIPアドレスでアクセスできない
  2. Windowsは、ファイアーウォールで外部からのアクセスを禁止している
  3. localhost以外にバインドしてIIS Expressを起動するには管理者権限が必要

IIS Expressを任意のアドレスにバインド

applicationHost.configを編集する必要があります。Visual Studio 2015では

IIS Expressでlocalhost以外のアドレスでアクセスする方法 - なか日記

プロジェクトの設定で「すべてのユーザーにサーバー設定を適用(プロジェクト ファイルに格納)」にチェックが入っている場合は、ソリューションを保存してるフォルダにある .vs (隠しフォルダ)に applicationhost.config が格納されいる

.vs/config/applicationHost.configを編集します。

<site name="ApiServer" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="\\vmware-host\Shared Folders\shigerunakajima\slot-marketing-dashboard\ApiServer" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:56043:localhost" />
    </bindings>
</site>

のような定義があります。バインドしたいIPアドレス・ドメイン名を設定します。
IPアドレス192.168.0.65を設定したい場合は

<binding protocol="http" bindingInformation="*:56043:192.168.0.65" />

を追加します。

<site name="ApiServer" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="\\vmware-host\Shared Folders\shigerunakajima\slot-marketing-dashboard\ApiServer" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:56043:localhost" />
        <binding protocol="http" bindingInformation="*:56043:192.168.0.65" />
    </bindings>
</site>

この状態で、IIS Expressを起動します。
ゲストOS(Windows)から接続するとBad Request - Invalid Hostnameが表示されます。

スクリーンショット 2016-06-27 16.25.06.png

回避するには Visual Studioを管理者権限で起動 します。

外部からアクセス

この時点ではホストOS外部から接続するとTimeoutします。
Windowsのファイアーウォールに阻まれます。

  1. Cortanaにfirewallと入力しエンターキーを押します。
  2. 操作(A) > 新しい規則(N)...
  3. 規則の種類ポート(O)を選択
  4. 次へ(N)をクリック
  5. 特定のローカルポート(S):56043を入力
  6. 次へ(N)をクリック
  7. 接続を許可する(A)を選択
  8. 次へ(N)をクリック
  9. この規則はいつ適用しますか?はデフォルトのまま
  10. 次へ(N)をクリック
  11. 名前(N):iis expressを入力
  12. 完了(F)をクリック

ポートや規則の名称は好きな値に設定してください。

管理者権限を使わずにIIS Expressを起動

上手くいきませんでした。

IIS Express で仮想サイトに複数のホスト名を割り当てる - しばやん雑記

netsh http add urlacl を叩けば管理者権限が要らない

と言う情報があります。実際に

netsh http add urlacl url=http://192.168.0.65:56043/ user=Everyone

を実行すると、デバック実行時にIIS Express Web サーバーを起動できません。と、表示されるようになります。
Visual Studio を管理者権限で起動すると、IIS Expressが起動できます。

次のパターンで試しました。

netsh http add urlacl url=http://192.168.0.65:56043/ user=luxiar201508\shigeru.nakajima
netsh http add urlacl url=http://192.168.0.65:56043/ user=shigeru.nakajima
netsh http add urlacl url=http://192.168.0.65:56043/ user=Administrator
netsh http add urlacl url=http://192.168.0.65:56043/ user=BUILTIN\Users
netsh http add urlacl url=http://192.168.0.65:56043/ user=BUILTIN\Administrators
netsh http add urlacl url=http://+:56043/ user=everyone

いずれも結果は同じでした。

Is netsh http add urlacl broken in Windows 10? - Microsoft Community が近いように思えます。回答はありません。

参考

45
44
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
44