Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've written the following code in Console. I want to display the string the code returns, on my Layout.cshtml page like any other things on the page. How can I do it using Web API?

 namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string serverName = "localhost";

            var nsm = new ServerManager();

            using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName))
            {

               //site mySite = sm.Sites.Add("Racing Cars Site", d:\inetpub\wwwroot
acing",  8080);
                int counter = 1; 
                foreach (var site in sm.Sites)
                {
                    //var p = site.Bindings.GetCollection().GetAttribute("physicalPath");
                    var p = site.Applications[0].VirtualDirectories[0].PhysicalPath;
                      int b=0;

                    foreach (Microsoft.Web.Administration.Binding binding in site.Bindings)
                         b= binding.EndPoint.Port;

                    Console.Write(String.Format(CultureInfo.InvariantCulture
                        , "Site number {0} : , {1} PhysicalPath : {2}  , Port:{3} {4} "
                        , counter.ToString(), site.Name ,p , b, Environment.NewLine));
                    counter++; 
                }
                Console.ReadKey();

            }
        }

    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
153 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your need is not related to Web API, forget about this. An ASP.NET MVC application is the way to go. As you said, it can be done using a helper but it exists easier ways to do that. (Using model or Viewbag). You will also need to learn how to use the markup of the rendering engine used in your view, like Razor. I suggest you to read some tutorials, starting from here for your issue, and here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...