Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:49:52+00:00 2026-06-02T10:49:52+00:00

I want to add a host header to a website which is working on

  • 0

I want to add a host header to a website which is working on IIS7 through a web application (asp.net 4.0 / C#).There are some examples in internet,but i guess most of them dont work on iis7.
(note:the web application is being hosted in same server so i guess there wont be a security problem while changing iis configurations)

Any help is appreciated,thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:49:56+00:00Added an answer on June 2, 2026 at 10:49 am

    I found this solution and it works for me.This is a little function with couple parameters,just you have to find the id of yourwebsite in your iss configuration.After that you have to give the ip adress of the server (iis),and port number,and hostname to the function and it will add a hostheader by using the parameters you entered.For example

    AddHostHeader(2, “127.0.0.1:81”, 81, “newsHostHeader”);

      static void AddHostHeader(int? websiteID, string ipAddress, int? port, string hostname)
        {
            using (var directoryEntry = new DirectoryEntry("IIS://localhost/w3svc/" + websiteID.ToString()))
            {
                var bindings = directoryEntry.Properties["ServerBindings"];
                var header = string.Format("{0}:{1}:{2}", ipAddress, port, hostname);
                if (bindings.Contains(header))
                  throw new InvalidOperationException("Host Header already exists!");
                bindings.Add(header);
                directoryEntry.CommitChanges();
            }
        }
    

    (note:do not forget to add to the page using
    System.DirectoryServices; using Microsoft.Web.Administration; )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website built with ASP.NET (3.5) and want add some level of
I am currently trying to configure an ASP.net Web Application through Web.config, to host
Our asp.net web site is currently deployed to an IIS7 server. We are setting
I want to add virtual host for the application quickstart but this error occur,
I have developed a web application, in which there's a functionality to enter note
Say we have a website that responds to a host header kebab-shop.intra.net Is is
I would like to setup a admin page (ASP.NET/C#) that can add IIS host
I want to add a scheduled task to a client's ASP.NET app. These posts
Does anybody know of a commercially supported distributable web server that can host ASP.NET
I have an ActiveX control (written in Delphi) which I want to host in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.