locked
window.location.hostname differs between app packages

    Question

  • I built a Windows Store app that uses HTML5/JavaScript and noticed that when you build the project and run it from Visual Studio, window.location.hostname is set to the project GUID.  When you build the app for Windows Store upload, window.location.hostname is set to "company name and app name" (e.g. xyzcorp.myapp).  Is this the expected behavior?

    Bret Zarkiewicz

    Wednesday, February 6, 2013 1:44 AM

Answers


  • Hi Bret,

    For Windows Store app built through javascript +HTML5, there is some difference comparing to the traditional webbrowser(IE) hosted web page. And the window.location.hostname seems also changed by the winjs runtime to supply windows store specific context information.

    #HTML, CSS, and JavaScript features and differences (Windows Store apps) (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx

    and the different hostname values you got at development time and published time(packaged for submitting windows store) is probably due to the fact that when you package the app for windows store submission, it will include the package identity (also the publisher idenity of your account) since those information will be needed for a formal published windows store app. And since you're going to supply some information for branding your windows store app, then I'd suggest you use some of the properties on the "Windows.ApplicationModel.Package" object (which is the recommended means to retrieve package and publisher information about your windows store app):

    #PackageId class (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br224668.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Wednesday, February 13, 2013 7:37 AM
    Thursday, February 7, 2013 3:43 AM
    Moderator

All replies

  • Hi tool4scs,

    the right API to use in this case is NetworkInformation.GetHostNames() and then for each host name look at the NetworkAdapter; if there is a network adapter on the hostname, then it’s an IP address.

    I would like to suggest you check the similar thread in the following link:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4f6a3933-f736-46a3-b848-e8694f21dd90

    NetworkInformation.GetHostNames

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.networkinformation.gethostnames.aspx

    Hope this helps, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 7, 2013 2:51 AM
    Moderator
  • Actually we are not looking for a local hostname lookup.  Our app is common codebase that can be built as a Metro app or as an app viewed in any web browser.  The latter case being where we started to use window.location.hostname to brand the app for particular OEM's that ship/sell our software.

    With that being said, when we implemented using window.location.hostname to brand the app, we noticed the Metro app reported this as the project GUID until we built the app for the Windows Store.  Then it changed to xyzcorp.myapp.  I am wondering where this information comes from and why it changes when using a local build opposed to a build for upload to the Windows Store.


    Bret Zarkiewicz

    Thursday, February 7, 2013 3:12 AM

  • Hi Bret,

    For Windows Store app built through javascript +HTML5, there is some difference comparing to the traditional webbrowser(IE) hosted web page. And the window.location.hostname seems also changed by the winjs runtime to supply windows store specific context information.

    #HTML, CSS, and JavaScript features and differences (Windows Store apps) (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx

    and the different hostname values you got at development time and published time(packaged for submitting windows store) is probably due to the fact that when you package the app for windows store submission, it will include the package identity (also the publisher idenity of your account) since those information will be needed for a formal published windows store app. And since you're going to supply some information for branding your windows store app, then I'd suggest you use some of the properties on the "Windows.ApplicationModel.Package" object (which is the recommended means to retrieve package and publisher information about your windows store app):

    #PackageId class (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br224668.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Wednesday, February 13, 2013 7:37 AM
    Thursday, February 7, 2013 3:43 AM
    Moderator
  • Steven,

    Thanks for the information.  The reason we are using window.location.hostname is because it is available across all platforms and we do not need to introduce platform specific code to accomplish the same task.  Thanks for the help and suggestion.


    Bret Zarkiewicz

    Thursday, February 7, 2013 3:13 PM