ASP.net不适用于某些用户代理生成JavaScript [英] ASP.net not generating javascript for some User Agents

查看:143
本文介绍了ASP.net不适用于某些用户代理生成JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

***************的 编辑2 ************* ****
我想通了这个问题...但我不喜欢的影响。我在测试我们的iPhone有针对性的移动应用较早,使用插件来掩盖Firefox的用户代理字符串作为一个iPhone。

***************Edit 2***************** I figured out the problem... But I don't like the implications. I was testing our iPhone targeted mobile application earlier and using a plugin to mask Firefox's User Agent String as an iPhone.

净是逸岸不产生所需的code的基础上那块单独的信息后背上。

.Net was infact NOT generating the required code for post backs based on that piece of information alone.

我不喜欢这种但是,因为自从iPhone和其它多媒体设备能够跨preT的javascript,ASP.net是打破依赖于服务器生成的JavaScript运行任何应用程序。

I do not like this however, because since the iPhone and other multimedia devices can interpret javascript, ASP.net is breaking any application that relies on server generated javascript to run.

因此​​,如果社会允许的话......我想改变我的官方回答的......为什么不ASP.net生成特定的浏览器的JavaScript,我怎么可以把这个功能了。

So, if the community will allow it... I'd like to change my official question to... Why will ASP.net not generate javascript for specific browsers and how can I turn this "feature" off.

*********** 结束编辑2 ***********

我有一个奇怪的问题。我复制从我的远程主机的一些工作code到我的工作电脑。当我尝试使用的页面,我得到一个JavaScript错误

I've got a weird problem. I copied some working code from my remote host to my computer at work. When I try to use the page I'm getting a javascript error

__doPostBack is not defined
javascript:__doPostBack('ctl00$ContentPlaceHolder1$login','')()()

在我几输出页面的源代码,果然没有服务器端生成的JavaScript。

When I few the output page source, sure enough there is no server side generated javascript.

我试图创建一个简单的页面:

I tried creating a simple page:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="jsTest.aspx.vb" Inherits="_jsTest" %>
<!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">
        <asp:TextBox ID="tbTest" runat="server"></asp:TextBox><br />
        <asp:LinkButton ID="linkTest" runat="server">LinkButton</asp:LinkButton>
    </form>
</body>
</html>

codebehind:

Codebehind:

Partial Class _jsTest
    Inherits System.Web.UI.Page
    Protected Sub linkTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkTest.Click
        Response.Write(tbTest.Text)
    End Sub
End Class

得到同样的错误。

Getting the same error.

我试图重新启动(嘿,它工作一半时间),清除了一切从APP_ code,Global.asax的web.config文件和补充一个文本框与自动回=真的......我走了的想法。

I've tried rebooting (hey, it works half the time), cleared out everything from App_Code, global.asax and web.config, added a textbox with autopostback=true... I'm out of ideas.

任何人都可以提供一些线索在这里发生了什么?

Can anyone shed some light on what's happening here?

*********的 更多信息 *********
我只是在IE中再次尝试了一切,它工作正常,页面的源代码所示:

*********More Information********* I just tried everything again in IE and it works as expected, the page source shows:

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkxNTA2MDE2NWRkxhZMwlMVwJprcVsvQLJLrTcgaSM=" />

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
<div>
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwK20LZAAuzRsusGAsz0+6YPxxO+Ewv1XsD5QKJiiprrGp+9a3Q=" />
</div>

而在Firefox源只显示:

While the source in Firefox only shows:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkxNTA2MDE2NWRkxhZMwlMVwJprcVsvQLJLrTcgaSM=" />

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwK20LZAAuzRsusGAsz0+6YPxxO+Ewv1XsD5QKJiiprrGp+9a3Q=" />

保存网页到桌面开放在记事本中揭示了同样的事情...

Saving the web pages to the desktop and opening in notepad reveals the same thing...

推荐答案

问题是默认的方式对待ASP.net未知的浏览器...比如iPhone。虽然这将是很好的假设未知的浏览器可以使用JavaScript ...你可以指定浏览器在web.config文件或machine.config中的部分是什么能力。

The problem is the default way ASP.net treats unknown browsers... such as the iPhone. Even though it would be nice to assume unknown browsers could use javascript... you can specify what capabilities that a browser has in the section of web.config or machine.config.

查看 http://slingfive.com/pages/$c$c/browserCaps/ 对于一个更新的browserCaps配置为asp.net文件

Check out http://slingfive.com/pages/code/browserCaps/ for an updated browsercaps config file for asp.net

下面是匹配基于Gecko浏览器的情况下的一个例子(Netscape 6以上,Mozilla的/火狐,...)

Here is an example of a case to match GECKO Based Browsers (Netscape 6+, Mozilla/Firefox, ...)

<case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)(?'VendorProductToken' (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)))?">
    			browser=Gecko
    			<filter>
    				<case match="(Gecko/[-\d]+)(?'VendorProductToken' (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)))">
    					type=${type}
    				</case>
    				<case> <!-- plain Mozilla if no VendorProductToken found -->
    					type=Mozilla
    				</case>
    			</filter>
    			frames=true
    			tables=true
    			cookies=true
    			javascript=true
    			javaapplets=true
    			ecmascriptversion=1.5
    			w3cdomversion=1.0
    			css1=true
    			css2=true
    			xml=true
    			tagwriter=System.Web.UI.HtmlTextWriter
    			<case match="rv:(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))">
    				version=${version}
    				majorversion=0${major}
    				minorversion=0${minor}
    				<case match="^b" with="${letters}">
    					beta=true
    				</case>
    			</case>
    		</case>

这篇关于ASP.net不适用于某些用户代理生成JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆