Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将C#脚本输出为html页面?_C#_Iis - Fatal编程技术网

如何将C#脚本输出为html页面?

如何将C#脚本输出为html页面?,c#,iis,C#,Iis,我通常用PHP和Python编写代码,但在这种情况下,我必须用C#编写代码 我有这个代码,它的工作非常好。它是一个控制台应用程序 但是你怎么能把它放到C#net上,这样就可以把它放到IIS上呢 基本上,它不应该将其输出到控制台,而应该将其写入浏览器 我试图搜索C#Web,但什么也找不到 谢谢你的帮助 using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Progr

我通常用PHP和Python编写代码,但在这种情况下,我必须用C#编写代码

我有这个代码,它的工作非常好。它是一个控制台应用程序

但是你怎么能把它放到C#net上,这样就可以把它放到IIS上呢

基本上,它不应该将其输出到控制台,而应该将其写入浏览器

我试图搜索C#Web,但什么也找不到

谢谢你的帮助

using System;
using System.Net;
using Independentsoft.Exchange;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential credential = new NetworkCredential("username", "password");
            Service service = new Service("https://myserver/ews/Exchange.asmx", credential);

            try
            {
                IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
                IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
                And restriction3 = new And(restriction1, restriction2);

                FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);

                for (int i = 0; i < response.Items.Count; i++)
                {
                    if (response.Items[i] is Appointment)
                    {
                        Appointment appointment = (Appointment)response.Items[i];

                        Console.WriteLine("Subject = " + appointment.Subject);
                        Console.WriteLine("StartTime = " + appointment.StartTime);
                        Console.WriteLine("EndTime = " + appointment.EndTime);
                        Console.WriteLine("Body Preview = " + appointment.BodyPlainText);
                        Console.WriteLine("----------------------------------------------------------------");
                    }
                }

                Console.Read();
            }
            catch (ServiceRequestException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine("Error: " + ex.XmlMessage);
                Console.Read();
            }
            catch (WebException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.Read();
            }
        }
    }
}
使用系统;
Net系统;
使用独立软件交换;
名称空间示例
{
班级计划
{
静态void Main(字符串[]参数)
{
NetworkCredential credential=新的网络凭据(“用户名”、“密码”);
服务=新服务(“https://myserver/ews/Exchange.asmx“,凭证);
尝试
{
IsGreaterThoreQualto restriction1=新IsGreaterThoreQualto(AppointmentPropertyPath.StartTime,DateTime.Today);
IsLessThanOrEqualTo restriction2=新的IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime,DateTime.Today.AddDays(1));
和限制3=新的和(限制1,限制2);
FindItemResponse response=service.FindItem(StandardFolder.Calendar,AppointmentPropertyPath.AllPropertyPath,restriction3);
对于(int i=0;i
编辑:我已尝试将其设置为asp.net页面 但它不会在屏幕上打印任何内容

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Plan.NBT.Final.Default" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="Independentsoft.Exchange" %>

<%
    NetworkCredential credential = new NetworkCredential("tedy", "123456889");
    Service service = new Service("https://area51.com/EWS/exchange.asmx", credential);

    try
    {
        IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
        IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
        And restriction3 = new And(restriction1, restriction2);

        FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);

        for (int i = 0; i < response.Items.Count; i++)
        {
            if (response.Items[i] is Appointment)
            {
                Appointment appointment = (Appointment)response.Items[i];

                Response.Write("Subject = " + appointment.Subject);
                Response.Write("StartTime = " + appointment.StartTime);
                Response.Write("EndTime = " + appointment.EndTime);
                Response.Write("Body Preview = " + appointment.BodyPlainText);
                Response.Write("----------------------------------------------------------------");
            }
        }

    }


     %>


ASP.NET是您正在寻找的答案。

ASP.NET是您正在寻找的答案。

好的,一个快速而肮脏的ASP.NET网页示例。基本上,你的主页面变成了页面负载。确保您的代码隐藏页继承System.Web.UI.Page(如果您使用的是VS2008或VS2010,那么它将为您处理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sample
{
    public partial class Sample: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            NetworkCredential credential = new NetworkCredential("username", "password");
            Service service = new Service("https://myserver/ews/Exchange.asmx", credential);

        try
        {
            IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
            IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
            And restriction3 = new And(restriction1, restriction2);

            FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);

            for (int i = 0; i < response.Items.Count; i++)
            {
                if (response.Items[i] is Appointment)
                {
                    Appointment appointment = (Appointment)response.Items[i];

                    lblSubject.Text = "Subject = " + appointment.Subject;
                    lblStartTime.Text = "StartTime = " + appointment.StartTime;
                    lblEndTime.Text = "EndTime = " + appointment.EndTime;
                    lblBodyPreview.Text = "Body Preview = " + appointment.BodyPlainText;

                }
            }


        }
        catch (ServiceRequestException ex)
        {
            lblError.Text= "Error: " + ex.Message;
            lblXmlError.Text = "Error: " + ex.XmlMessage;
            Console.Read();
        }
        catch (WebException ex)
        {
            lblWebError.Text = "Error: " + ex.Message;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
名称空间示例
{
公共部分类示例:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
NetworkCredential credential=新的网络凭据(“用户名”、“密码”);
服务=新服务(“https://myserver/ews/Exchange.asmx“,凭证);
尝试
{
IsGreaterThoreQualto restriction1=新IsGreaterThoreQualto(AppointmentPropertyPath.StartTime,DateTime.Today);
IsLessThanOrEqualTo restriction2=新的IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime,DateTime.Today.AddDays(1));
和限制3=新的和(限制1,限制2);
FindItemResponse response=service.FindItem(StandardFolder.Calendar,AppointmentPropertyPath.AllPropertyPath,restriction3);
对于(int i=0;i
}

然后你的viewpage可能是这样的。确保CodeBehind指向具有代码的类来完成页面的所有繁重工作

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sample.aspx.cs"     Inherits="SecureCareEnrollment.WebForms.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <label id="lblSubject" runat="server"></label><br />
            <label id="lblStartTime " runat="server"></label><br />
            <label id="lblEndTime " runat="server"></label><br />
            <label id="lblBodyPreview" runat="server"></label><br />
----------------------------------------------------------------<br />
            <label id=lblError" runat="server"></label><br />
            <label id=lblXmlError" runat="server"></label><Br />
            <label id=lblWebError" runat="server"></label>
    </div>
    </form>
</body>
</html>





----------------------------------------------------------------


好的,一个快速脏的asp.net网页示例。基本上你的主页面变成了页面加载。确保你的代码隐藏页面继承System.Web.UI.Page(如果你使用的是VS2008或VS2010,那么它会为你处理

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sample
{
    public partial class Sample: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            NetworkCredential credential = new NetworkCredential("username", "password");
            Service service = new Service("https://myserver/ews/Exchange.asmx", credential);

        try
        {
            IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
            IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
            And restriction3 = new And(restriction1, restriction2);

            FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);

            for (int i = 0; i < response.Items.Count; i++)
            {
                if (response.Items[i] is Appointment)
                {
                    Appointment appointment = (Appointment)response.Items[i];

                    lblSubject.Text = "Subject = " + appointment.Subject;
                    lblStartTime.Text = "StartTime = " + appointment.StartTime;
                    lblEndTime.Text = "EndTime = " + appointment.EndTime;
                    lblBodyPreview.Text = "Body Preview = " + appointment.BodyPlainText;

                }
            }


        }
        catch (ServiceRequestException ex)
        {
            lblError.Text= "Error: " + ex.Message;
            lblXmlError.Text = "Error: " + ex.XmlMessage;
            Console.Read();
        }
        catch (WebException ex)
        {
            lblWebError.Text = "Error: " + ex.Message;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
名称空间示例
{
公共部分类示例:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
NetworkCredential credential=新的网络凭据(“用户名”、“密码”);
服务=新服务(“https://myserver/ews/Exchange.asmx“,凭证);
尝试
{
IsGreater Thorequalto restriction1=新IsGreater Thorequal