我有两个申请 应用1:桌面控制台应用 应用2:ASP Dot Net Web Application
我提交了一个表单应用程序1,因此应该启动一个回发事件。只要我在Application2(Web App)的web.config中强制执行HttpRuntime点网版本4.7,它就会这样做。 postBack停止射击。
<httpRuntime targetFramework="4.7" maxRequestLength="2097151"/>
申请1&#39>代码:
private static string m_autoLoginFormContents = null;
static void Main()
{
//DECLARE INTERNET EXPLORER OBJECT
SHDocVw.InternetExplorer m_autologinIEWindow = new SHDocVw.InternetExplorer();
//ASSOCIATE HANDLER TO DOCUMENT COMPLETE EVENT
m_autologinIEWindow.DocumentComplete += URLAutologinDocumentCompleteEventHandler;
//NAVIGATE THE URL
m_autologinIEWindow.Navigate("about:blank");
m_autologinIEWindow.AddressBar = true;
m_autologinIEWindow.Visible = true;
System.Console.Read();
}
//HANDLER DEFINITION
public static void URLAutologinDocumentCompleteEventHandler(object senderObject, ref object objectTwo /* not sure what this argument is for */)
{
System.Console.Write("I am here in Document Complete");
m_autoLoginFormContents = "<form runat = \"server\" name = \"AutoLoginForm\" action = \"http://localhost:12810/ei/Login.aspx\" method = POST><input type = hidden name = \"tbUsername\" value = \"ECTNAMbarora\"><input type = hidden name = \"tbPassword\" value = \"Barora1#1\"><input type = hidden name = \"__VIEWSTATE\" value = \"/wEPDwUKMTUxNzY2NTkwNQ9kFgICAw9kFgICAQ9kFgJmD2QWAgIBD2QWAgIBDw8WAh4HVmlzaWJsZWhkZGTOFG2synRTKe8uLtoYBL1c8DCnow==\"><input type = hidden name = \"__EVENTARGUMENT\" value = \"\"><input type = hidden name = \"__EVENTTARGET\" value = \"\"><input type = hidden name = \"__EVENTVALIDATION\" value = \"/wEWBQKInY2gBALStq24BwK3jsrkBAKC3IeGDAKVyIalD9DFZ+2yZSlAiApijC71lY9wtsqo\"><input type = hidden name = \"utcOffset\" value = \"8\"><input type = hidden name = \"btnLogin\" value = \"Login\">";
SHDocVw.InternetExplorer IE = senderObject as SHDocVw.InternetExplorer;
mshtml.HTMLDocument document = IE.Document as mshtml.HTMLDocument;
document.body.insertAdjacentHTML("afterBegin", m_autoLoginFormContents);
mshtml.IHTMLFormElement formElement = document.forms.item("AutoLoginForm") as mshtml.IHTMLFormElement;
formElement.submit();
System.Console.ReadKey();
}
申请2:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack){
//System.Console.Read();
System.Console.Write("Bhavya has reached postback");
}
}
如果我强制执行,它永远不会进入IsPostBack Block。
注意:
我原来的问题是没有解雇的事件,我写了一个简短的代码来显示问题。
不确定是否存在问题,
我找到了一个页面,其中说事件处理已经破解并告诉我一条路,但我不知道如何做到这一点,HttpModule名称是什么等等,因为我是Dot Net Programming的新手!
说明工作的页面:
https://docs.microsoft.com/en-us/aspnet/whitepapers/aspnet4/breaking-changes#0.1__Toc256770154
修改
我尝试添加:
<httpRuntime targetFramework="4.7" maxRequestLength="2097151" requestValidationMode="2.0"/>
和
validateRequest="false"
用于关闭请求验证,但仍然遇到问题
答案 0 :(得分:-1)
if(Page.IsPostBack)
{
.......
}