win form 中可行的COM 组件为什么移到web form 就不行了呢?高手指点
Imports System.Reflection
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form 設計工具產生的程式碼 "
'此為 Web Form 設計工具所需的呼叫。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
'請勿刪除或移動它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
'請勿使用程式碼編輯器進行修改。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在這裡放置使用者程式碼以初始化網頁
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
oApp = Server.CreateObject("Outlook.Application")
' Get Mapi NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Create an AppointmentItem.
Dim oAppt As Outlook._AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
'oAppt.Display(true) 'Modal
' Change AppointmentItem to a Meeting.
oAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting
' Set some common properties.
oAppt.Subject = "Meeting Request Test"
oAppt.Body = "Hello World"
oAppt.Location = "B503"
oAppt.Start = Convert.ToDateTime("12/22/2003 9:00:00 AM")
oAppt.End = Convert.ToDateTime("12/22/2003 1:00:00 PM")
oAppt.ReminderSet = True
oAppt.ReminderMinutesBeforeStart = 5
oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy ' olBusy
oAppt.IsOnlineMeeting = False
oAppt.AllDayEvent = False
' Add attendees.
Dim oRecipts As Outlook.Recipients = oAppt.Recipients
' Add required attendee.
Dim oRecipt As Outlook.Recipient
oRecipt = oRecipts.Add("johnlenfu") ' TODO:
oRecipt.Type = Outlook.OlMeetingRecipientType.olRequired
' Add optional attendee.
oRecipt = oRecipts.Add("windyxiao") ' TODO:
oRecipt.Type = Outlook.OlMeetingRecipientType.olOptional
oRecipts.ResolveAll()
'oAppt.Display(true)
' Send out request.
oAppt.Send()
' Logoff.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oAppt = Nothing
oRecipts = Nothing
oRecipt = Nothing
End Sub
End Class
一下是在asp.net中发送outlook 会议邀请的一段代码,该代码在win form 中运行正常,可到了web form 中出错如下
'/appointment1' 應用程式中發生伺服器錯誤。
--------------------------------------------------------------------------------
存取被拒。
描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。
例外詳細資訊: System.UnauthorizedAccessException: 存取被拒。
沒有授權 ASP.NET 存取要求的資源。請考慮將資源存取權授予 ASP.NET 要求識別。ASP.NET 有一個基本處理序識別 (通常在 IIS 5 上為 {MACHINE}\ASPNET,在 IIS 6 上為 Network Service),會在應用程式未模擬的情況下使用。如果應用程式是透過 <identity impersonate="true"/> 模擬,這個識別將會是匿名使用者 (通常為 IUSR_MACHINENAME) 或經過驗證的要求使用者。
若要取得 ASP.NET 寫入檔案的存取權限,請在檔案總管中以右鍵按一下檔案,選擇 [內容] 並選取 [安全] 索引標籤。按一下 [新增] 加入適當的使用者或群組。反白顯示 ASP.NET 帳戶,並且選取所需存取權限的核取方塊。
原始程式錯誤:
行 29: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
行 30:
行 31: Dim oApp As Outlook.Application = New Outlook.Application
行 32: ' Get Mapi NameSpace and Logon.
行 33: Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
原始程式檔: c:\inetpub\wwwroot\appointment1\WebForm1.aspx.vb 行: 31
win form 中玩的好好的程序,为什么到了win form 中就不好玩了呢?