API布局页的C#的输入

API布局页的C#的输入

本文介绍了使用Web API布局页的C#的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在控制台下面code。我想要显示的字符串code的回报,我Layout.cshtml页面上,如页面上的任何其他东西。我该怎么办使用Web API呢?

 命名空间的ConsoleApplication1
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            字符串服务器名=localhost的;            VAR NSM =新ServerManager的();            使用(Microsoft.Web.Administration.ServerManager SM = Microsoft.Web.Administration.ServerManager.OpenRemote(服务器))
            {               //网站MYSITE = sm.Sites.Add(赛车网站D:\\\\ \\\\的Inetpub wwwroot文件\\赛车,8080);
                INT计数器= 1;
                的foreach(在sm.Sites VAR网站)
                {
                    //变种P = site.Bindings.GetCollection()的getAttribute(physicalPath);
                    变种p值= site.Applications [0] .VirtualDirectories [0] .PhysicalPath;
                      INT B = 0;                    的foreach(Microsoft.Web.Administration.Binding在site.Bindings绑定)
                         B = binding.EndPoint.Port;                    Console.Write(的String.Format(CultureInfo.InvariantCulture
                        网站数{0},{1} PhysicalPath:{2},端口:{3} {4}
                        ,counter.ToString(),site.Name,P,B,Environment.NewLine));
                    反++;
                }
                Console.ReadKey();            }
        }    }
}


解决方案

如果您希望这些codeS在 MVC 你需要创建 MVC 应用程序。没有其他办法做到这一点,在这种情况下。

尝试重写,在 MVC 。顺便说一句,如果你想显示在控制台应用程序的输出您必须使用调试

下面是例子:

  System.Diagnostics.Debug.WriteLine(字符串);

因此​​,这意味着调试控制台 code在 MVC

更新:如果你想显示在网页上,你必须重写codeS在 MVC 应用程序中的codeS的结果。

您还问,如果你想使用助手,所以我应该说,你绝对可以使用 MVC 助手。

希望它帮助。

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\racing",  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();

            }
        }

    }
}
解决方案

If you want these codes in MVC you need to create MVC application. No other way to do it, in that case.

Try to rewrite that in MVC. By the way if you want to show the output in the console application you must use Debug for that.

Here is the example :

System.Diagnostics.Debug.WriteLine("The String");

So it means debug is the console code in MVC.

Update : If you want to show the result of your codes in web pages you have to rewrite your codes in MVC application.

You also asked if you want to use helpers, so I should say you can definitely use MVC helpers.

Hope it helps.

这篇关于使用Web API布局页的C#的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:23