XMLHTTP POST 请求和 System.Reflection

发布于 2024-07-08 13:23:52 字数 1061 浏览 7 评论 0原文

我有一个 DTS 作业,它使用 MSXML2.XMLHTTP3.0 对象生成对 ASP.NET 应用程序的发布请求。 在幕后,ASP.NET 应用程序正在使用 System.Reflection 来获取一些程序集信息,我收到以下异常:

System.Web.HttpException 错误代码: -2147467259 消息会话状态只能在enableSessionState时使用 设置为 true,无论是在 配置文件或页面中 指示。 另请确保 System.Web.SessionStateModule 或 自定义会话状态模块是 包含在 \ 部分中 应用程序配置。

DTS 作业代码:

Dim objSvHTTP
Dim PostData

Set objSvHTTP = CreateObject("Msxml2.XMLHTTP.3.0")
objSvHTTP.open "POST", "http://www.mywebsite.com", false
objSvHTTP.send

If (objSvrHTTP.responseText = "") Then
    //do something
Else
    //do somethiing else
End If

ASP.NET 应用程序代码:

string WebPath = "D:\mywebsite\bin\mywebsite.dll";
Assembly UI = Assembly.LoadFrom( @WebPath );
Type t = UI.GetType( "MyWebsite.BasePage" );
MethodInfo MyMethod = t.GetMethod( "MyMethod" );
object obj = Activator.CreateInstance(t); 
MyMethod.Invoke( obj, null);

问题是,我是否需要在对 ASP.NET 应用程序的 XMLHTTP 请求中提供有效的 Active Directory 凭据以避免出现错误消息

I have a DTS job that is using the MSXML2.XMLHTTP3.0 object to generate a post request to an ASP.NET application. Under the covers, the ASP.NET application is using System.Reflection to acquire some assembly information and I receive the following exception:

System.Web.HttpException Error Code:
-2147467259 Message Session state can only be used when enableSessionState
is set to true, either in a
configuration file or in the Page
directive. Please also make sure that
System.Web.SessionStateModule or a
custom session state module is
included in the \ section in the
application configuration.

DTS Job Code:

Dim objSvHTTP
Dim PostData

Set objSvHTTP = CreateObject("Msxml2.XMLHTTP.3.0")
objSvHTTP.open "POST", "http://www.mywebsite.com", false
objSvHTTP.send

If (objSvrHTTP.responseText = "") Then
    //do something
Else
    //do somethiing else
End If

ASP.NET Application Code:

string WebPath = "D:\mywebsite\bin\mywebsite.dll";
Assembly UI = Assembly.LoadFrom( @WebPath );
Type t = UI.GetType( "MyWebsite.BasePage" );
MethodInfo MyMethod = t.GetMethod( "MyMethod" );
object obj = Activator.CreateInstance(t); 
MyMethod.Invoke( obj, null);

Question is, do I need to provide vaild Active Directory credentials in the XMLHTTP request to the ASP.NET application to avoid the error message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等往事风中吹 2024-07-15 13:23:52

从异常消息来看,这对我来说看起来不像是身份验证问题。
调用的方法是否会尝试访问 ASP.NET 会话? 这可以解释这个例外。

Judging by the exception message this does not look like an authentication problem to me.
Could it be that the invoked method tries to access the ASP.NET Session? That would explain the exception.

深海里的那抹蓝 2024-07-15 13:23:52

@Israr Khan:

我们最终找到了一个解决方法,即当 DTS 调用该过程所需的特定网页时不执行反射代码。

这可以解释为什么当我们尝试在开发和生产环境中解决此问题时,会得到不同的结果。 我对每个环境中的 web.config 文件进行了比较,发现 HttpModules 部分中的 Session 引用位于我们的生产环境中,但不在我们的开发环境中。

该过程在开发中有效,但在生产中无效。 我已将此建议提交给我的同事,看看他们是否想尝试此解决方案而不是解决方法。

@Israr Khan:

We eventually found a workaround by not executing the reflection code when the DTS called the particular web page that was required for the process.

This would explain why we were getting mixed results when we were trying to resolve this issue in our development and production environments. I did a comparison of the web.config files in each environment and noticed that the Session reference in the HttpModules section was in our production environment, but not in our development environment.

The process worked in development and did not work in production. I have submitted this suggestion to my co-workers to see if they want to try this solution instead of the workaround.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文