回发后查询字符串缺失值

时间:2017-02-05 16:11:21

标签: asp.net webcam.js

我使用webcam.js使用asp.net网络表单应用从网络摄像头获取照片。问题是,我想根据" ID"获取文件名。请求参数。但每次我点击"拍摄"按钮,查询字符串值没什么。

这是我完整的HTML:

<%@ Page Language="vb" AutoEventWireup="false"  CodeBehind="Coba.aspx.vb" Inherits="myWebcam.Coba" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src='<%=ResolveUrl("~/Plugin/jquery.webcam.js")%>' type="text/javascript"></script>
    <script type="text/javascript">
        var pageUrl = '<%=ResolveUrl("~/Coba.aspx")%>';
        $(function (){
           $("#Camera").webcam({
                 width: 320,
                 height: 240,
                 mode: "save",
                 swffile: '<%=ResolveUrl("Plugin/jscam.swf")%>',
                 onTick: function () { },
                 onSave: function () {
                 },
                 onCapture: function () {
                     webcam.save(pageUrl);
                 },
                 debug: function () { },
                 onLoad: function () { }
             });
        });

        function Capture() {

            webcam.capture();

            return false;
        };
     </script>
</head>
<body>
    <form id="form1" runat="server">

    <div>
    <h2>Index</h2>

    <input type="button" value="Shoot!" onclick="Capture()" />
    <div id="Camera"></div>
    </div>
    </form>
</body>
</html>

这是我的asp.net代码隐藏:

Imports System.IO
Imports System.Web.Services

Public Class Coba
    Inherits System.Web.UI.Page
    Public sID As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        sID = Request.QueryString("id")


        If Not Page.IsPostBack Then

            Capture(Trim(sID))
        End If
    End Sub
    Public Sub Capture(ByVal mID As String)
        Dim stream = Request.InputStream
        Dim dump As String

        If stream.Length > 0 Then

            Using reader = New StreamReader(stream)
                dump = reader.ReadToEnd()
            End Using

            Dim path = Server.MapPath("~/" & Trim(mID) & ".jpg")
            System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump))
        End If
    End Sub

    Private Function String_To_Bytes2(strInput As String) As Byte()
        Dim numBytes As Integer = (strInput.Length) / 2
        Dim bytes As Byte() = New Byte(numBytes - 1) {}

        For x As Integer = 0 To numBytes - 1
            bytes(x) = Convert.ToByte(strInput.Substring(x * 2, 2), 16)
        Next

        Return bytes
    End Function
End Class

我第一次运行该页面时,我可以获得&#34; id&#34;来自查询字符串的值。拍摄按钮触发回发并运行&#34; Capture&#34; sub但是&#34; id&#34; querystring什么都不返回。

针对此问题的任何解决方案?

1 个答案:

答案 0 :(得分:1)

我尝试了代码,我认为存在错误概念。该插件似乎没有附加任何QueryString。你的身份证总是没有。我进行了调试,发现QueryString中没有添加ID的痕迹。

文件名是您自己为逻辑分配的属性。 Here is a complete example in which the ID is not recovered.

即使在official page of the plugin中,也没有通过Querystring引用ID。

其他方面,您不应该使用相同的页面进行界面和保存过程。始终调用Pageload,即使加载接口也会调用Capture(Trim(sID))

我认为你必须改变这一行:

var pageUrl = '<%=ResolveUrl("~/Coba.aspx")%>';

var pageUrl = '<%=ResolveUrl("~/Coba_SaveImage.aspx")%>';

所有代码隐藏都在页面Coba_SaveImage.aspx中。在页面加载中不需要If Not Page.IsPostBack Then始终是回发。

希望这对你有所帮助。