Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

asp.net mvc - C# input on Layout page using Web API

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...