teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

質問時点以降に試したことを追記しました。

2018/11/09 07:47

投稿

tipsy
tipsy

スコア11

title CHANGED
File without changes
body CHANGED
@@ -39,7 +39,7 @@
39
39
  本来アクセスしたいURL(例):https://xxxxxxx/login.jsp
40
40
  エラー時に取得したURL(例):https://xxxxxxx/login.jsp?Try=y
41
41
 
42
- WebAPI→A.exe呼び出し
42
+ WebAPI→A.exe呼び出し(2018/10/31追記)
43
43
  ```VB
44
44
  Dim MyProc As Process
45
45
  MyProc = New Process
@@ -48,7 +48,7 @@
48
48
  MyProc.StartInfo.Arguments = "99999" '引数はユーザーID
49
49
  MyProc.Start()
50
50
  ```
51
- A.exe→B.exe呼び出し
51
+ A.exe→B.exe呼び出し(2018/10/31追記)
52
52
  ```VB
53
53
  Dim procUp As New Process
54
54
  procUp.StartInfo.FileName = "C:\xxxxx\B.exe"
@@ -73,7 +73,7 @@
73
73
  End If
74
74
  ```
75
75
 
76
- B.exe内のWebBrowser関連の処理
76
+ B.exe内のWebBrowser関連の処理(2018/10/31追記)
77
77
  ```VB
78
78
  Public WithEvents WebBrowser1 As New WebBrowser2()
79
79
  Private pURL As String = "https://xxxxxxx/"
@@ -107,7 +107,7 @@
107
107
  End If
108
108
  End Sub
109
109
  ```
110
- WebBrowser2クラス
110
+ WebBrowser2クラス(2018/10/31追記)
111
111
  (他の人が作りかけていたものを引き継いで手探りで調べながら作成しためコメントに誤りがあるかもしれません。)
112
112
  ```VB
113
113
  Imports System.Runtime.InteropServices
@@ -301,4 +301,23 @@
301
301
  ・ASP.NET v4.0
302
302
  ・Visual Studio 2013
303
303
  ・本番サーバ:Windows Server 2012 R2(IIS Version 8.5.9600.16384)
304
- ・開発環境:Windows 7 Professional(IIS Version 7.5.7600.16385)
304
+ ・開発環境:Windows 7 Professional(IIS Version 7.5.7600.16385)
305
+
306
+ ### 他に試したこと2
307
+ ・アプリケーションプールの詳細設定でアプリケーションプールのIDを
308
+  DefaultAppPoolから管理者権限のあるユーザーに変更。(2018/11/09追記)
309
+ 期待した動作は得られるようになりましたが下記の理由で没に。現在は設定していません。
310
+ ・アプリケーションプールの権限が強すぎてセキュリティ面に不安がある。
311
+ ・確認した日によって動作が変わるが、理由が不明。
312
+  【サーバーメンテナンス前】
313
+   ・Administartorsグループのユーザーだとクッキー無効時のエラー画面に遷移。
314
+   ・Administratorがログイン状態でないとクッキー無効時のエラー画面に遷移。
315
+  【サーバーメンテナンス後】
316
+   ・Administratorsグループのユーザーでも正常動作。
317
+   ・ログイン状態でなくても正常動作。
318
+
319
+ ・WebBrowserControl.exeのバージョンをIE11に設定。(2018/11/09追記)
320
+ →クッキー無効時のエラー画面に遷移。
321
+
322
+ ・HTTPClientでの実装(2018/11/09追記)
323
+ クッキーの一部が取得できませんでした。ブラウザでサイトを開いたときの動作をFiddlerで確認したところ、ログインページのソースで指定されている外部スクリプトをGET後、その内部の処理で作成したURLをGETしてCookieの設定を追加しているようでした。作成されるURLは毎回変わります。(用語・表現が正確ではないかもしれません。)JavaScriptはブラウザで実行するもの、という認識のためHTTPClientのみではログイン不可能なサイトだと考えています。

1

それぞれの呼び出し部分のコードとWebBrowserについて追記しました。

2018/11/09 07:47

投稿

tipsy
tipsy

スコア11

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  どこをどう修正すればいいのか検討がつかない状態です。
8
8
 
9
9
  私自身がWeb系開発の初心者で、
10
- 周囲にもASP.NET Web フォームアプリケーション開発の経験者がいないため
10
+ 周囲にもASP.NET Web フォームアプリケーション開発に詳しい人がいないため
11
11
  初歩的な知識が抜けている可能性があります。
12
12
 
13
13
  特定条件でのみ発生するため、環境の違いが原因だと考えています。
@@ -39,6 +39,230 @@
39
39
  本来アクセスしたいURL(例):https://xxxxxxx/login.jsp
40
40
  エラー時に取得したURL(例):https://xxxxxxx/login.jsp?Try=y
41
41
 
42
+ WebAPI→A.exe呼び出し
43
+ ```VB
44
+ Dim MyProc As Process
45
+ MyProc = New Process
46
+ MyProc.EnableRaisingEvents = False
47
+ MyProc.StartInfo.FileName = "C:\xxxxx\A.exe"
48
+ MyProc.StartInfo.Arguments = "99999" '引数はユーザーID
49
+ MyProc.Start()
50
+ ```
51
+ A.exe→B.exe呼び出し
52
+ ```VB
53
+ Dim procUp As New Process
54
+ procUp.StartInfo.FileName = "C:\xxxxx\B.exe"
55
+ '引数はエラーログとサイトでのアップロードに使用するファイルのパス
56
+ procUp.StartInfo.Arguments = "C:\xxxxx\err.txt" & " " & "C:\xxxxx\upload.csv"
57
+
58
+ Try
59
+ procUp.Start()
60
+ Catch ex As Exception
61
+ 'exeの実行で例外が出た場合は即中止
62
+ MyErrStream = New StreamWriter(wErrFilePath, True, System.Text.Encoding.GetEncoding("Shift-JIS"))
63
+ MyErrStream.WriteLine("B.exe実行時に例外が発生しました。(" & ex.GetType().ToString & ")")
64
+ ExeErrFG = True
65
+ End Try
66
+
67
+ If ExeErrFG = False Then
68
+ procUp.WaitForExit(600000)
69
+ If procUp.HasExited = False Then
70
+ procUp.Kill()
71
+ End If
72
+ '(省略)
73
+ End If
74
+ ```
75
+
76
+ B.exe内のWebBrowser関連の処理
77
+ ```VB
78
+ Public WithEvents WebBrowser1 As New WebBrowser2()
79
+ Private pURL As String = "https://xxxxxxx/"
80
+
81
+ Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
82
+
83
+ '(省略)
84
+
85
+ '拡張したWebBrowser2をFormに追加
86
+ WebBrowser1.Dock = DockStyle.Fill
87
+ Controls.Add(WebBrowser1)
88
+ WebBrowser1.ScriptErrorsSuppressed = True
89
+ WebBrowser1.Navigate(pURL & "login.jsp") 'ログイン画面
90
+ End Sub
91
+
92
+ Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
93
+ '「試したこと」に記載しているクッキーのチェックを行ったコード
94
+ 'MyWStream.WriteLine("url:" & WebBrowser1.Document.Url.ToString)
95
+ 'MyWStream.WriteLine("cookie:" & WebBrowser1.Document.Cookie)
96
+
97
+ If Environment.ExitCode = 9 Then
98
+ Application.Exit()
99
+ Else
100
+ If WebBrowser1.Document.Url.ToString.Contains(pURL) Then
101
+ '画面ごとに必要なhtml要素の有無を確認してから操作していく処理(省略)
102
+ Else
103
+ MyWStream.WriteLine("URLが不正です。(" & WebBrowser1.Document.Url.ToString & ")")
104
+ AppCloseRtn(9)
105
+ Exit Sub
106
+ End If
107
+ End If
108
+ End Sub
109
+ ```
110
+ WebBrowser2クラス
111
+ (他の人が作りかけていたものを引き継いで手探りで調べながら作成しためコメントに誤りがあるかもしれません。)
112
+ ```VB
113
+ Imports System.Runtime.InteropServices
114
+ Imports System.Security.Permissions
115
+
116
+ Public Class WebBrowser2
117
+ Inherits WebBrowser
118
+
119
+ Private cookie As AxHost.ConnectionPointCookie
120
+ Private helper As WebBrowser2EventHelper
121
+
122
+ 'イベントデリゲートの宣言
123
+ Public Event NavigateError As WebBrowserNavigateErrorEventHandler
124
+
125
+ 'デリゲートの宣言
126
+ Public Delegate Sub WebBrowserNavigateErrorEventHandler(ByVal sender As Object, _
127
+ ByVal e As WebBrowserNavigateErrorEventArgs)
128
+
129
+ <PermissionSetAttribute(SecurityAction.LinkDemand, _
130
+ Name:="FullTrust")> Protected Overrides Sub CreateSink()
131
+
132
+ '派生元クラスのCreateSinkを呼び出す
133
+ MyBase.CreateSink()
134
+
135
+ 'コントロールのイベント処理をActiveXに接続する
136
+ helper = New WebBrowser2EventHelper(Me)
137
+ cookie = New AxHost.ConnectionPointCookie( _
138
+ Me.ActiveXInstance, helper, GetType(DWebBrowserEvents2))
139
+
140
+ End Sub
141
+
142
+ <PermissionSetAttribute(SecurityAction.LinkDemand, _
143
+ Name:="FullTrust")> Protected Overrides Sub DetachSink()
144
+
145
+ 'ActiveXに接続されているコントロールのイベント処理を解放する
146
+ If cookie IsNot Nothing Then
147
+ cookie.Disconnect()
148
+ cookie = Nothing
149
+ End If
150
+
151
+ '派生元クラスのDetachSinkを呼び出す
152
+ MyBase.DetachSink()
153
+
154
+ End Sub
155
+
156
+ 'ActiveXからのナビゲートエラーイベントによるコールバック
157
+ Protected Overridable Sub OnNavigateError( _
158
+ ByVal e As WebBrowserNavigateErrorEventArgs)
159
+
160
+ RaiseEvent NavigateError(Me, e)
161
+
162
+ End Sub
163
+
164
+ 'NavigateErrorイベント情報クラス
165
+ Private Class WebBrowser2EventHelper
166
+ Inherits StandardOleMarshalObject
167
+ Implements DWebBrowserEvents2
168
+
169
+ Private parent As WebBrowser2
170
+
171
+ Public Sub New(ByVal parent As WebBrowser2)
172
+ Me.parent = parent
173
+ End Sub
174
+
175
+ Public Sub NavigateError(ByVal pDisp As Object, _
176
+ ByRef URL As Object, ByRef frame As Object, _
177
+ ByRef statusCode As Object, ByRef cancel As Boolean) _
178
+ Implements DWebBrowserEvents2.NavigateError
179
+
180
+ ' Raise the NavigateError event.
181
+ Me.parent.OnNavigateError( _
182
+ New WebBrowserNavigateErrorEventArgs( _
183
+ CStr(URL), CStr(frame), CInt(statusCode), cancel))
184
+
185
+ End Sub
186
+
187
+ End Class
188
+
189
+ End Class
190
+
191
+ 'NavigateErrorイベントのプロパティセット
192
+ Public Class WebBrowserNavigateErrorEventArgs
193
+ Inherits EventArgs
194
+
195
+ Private urlValue As String
196
+ Private frameValue As String
197
+ Private statusCodeValue As Int32
198
+ Private cancelValue As Boolean
199
+
200
+ Public Sub New( _
201
+ ByVal url As String, ByVal frame As String, _
202
+ ByVal statusCode As Int32, ByVal cancel As Boolean)
203
+
204
+ Me.urlValue = url
205
+ Me.frameValue = frame
206
+ Me.statusCodeValue = statusCode
207
+ Me.cancelValue = cancel
208
+
209
+ End Sub
210
+
211
+ Public Property Url() As String
212
+ Get
213
+ Return urlValue
214
+ End Get
215
+ Set(ByVal value As String)
216
+ urlValue = value
217
+ End Set
218
+ End Property
219
+
220
+ Public Property Frame() As String
221
+ Get
222
+ Return frameValue
223
+ End Get
224
+ Set(ByVal value As String)
225
+ frameValue = value
226
+ End Set
227
+ End Property
228
+
229
+ Public Property StatusCode() As Int32
230
+ Get
231
+ Return statusCodeValue
232
+ End Get
233
+ Set(ByVal value As Int32)
234
+ statusCodeValue = value
235
+ End Set
236
+ End Property
237
+
238
+ Public Property Cancel() As Boolean
239
+ Get
240
+ Return cancelValue
241
+ End Get
242
+ Set(ByVal value As Boolean)
243
+ cancelValue = value
244
+ End Set
245
+ End Property
246
+
247
+ End Class
248
+
249
+ ' NavigateErrorのインターフェース定義
250
+ <ComImport(), Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D"), _
251
+ InterfaceType(ComInterfaceType.InterfaceIsIDispatch), _
252
+ TypeLibType(TypeLibTypeFlags.FHidden)> _
253
+ Public Interface DWebBrowserEvents2
254
+
255
+ <DispId(271)> Sub NavigateError( _
256
+ <InAttribute(), MarshalAs(UnmanagedType.IDispatch)> _
257
+ ByVal pDisp As Object, _
258
+ <InAttribute()> ByRef URL As Object, _
259
+ <InAttribute()> ByRef frame As Object, _
260
+ <InAttribute()> ByRef statusCode As Object, _
261
+ <InAttribute(), OutAttribute()> ByRef cancel As Boolean)
262
+
263
+ End Interface
264
+ ```
265
+
42
266
  ### 試したこと
43
267
  エラー画面でクッキーが無効という旨が記載されていたため、
44
268
  B.exeを実行する状況の条件を変えながらクッキーの確認を行いました。