webapp的话,用html5上传文件不就行了,plupload应该有html5上传文件的吧
好吧 我找找
用plupload还要写个后台程序放在IIS上接收上传图片
我写的服务端是websocket
大神会不会直接用websocket做上传文件捏
@小白菜呀: 很久没用过socket了!websocket在低版本浏览器不可以用,也没用过,明天看看给你写个demo吧
@秋壶冰月: 多谢 多谢
1 public class WSHandler : IHttpHandler 2 { 3 public void ProcessRequest(HttpContext context) 4 { 5 if (context.IsWebSocketRequest) 6 { 7 context.AcceptWebSocketRequest(ProcessWSChat); 8 } 9 } 10 11 public bool IsReusable { get { return false; } } 12 13 private async Task ProcessWSChat(AspNetWebSocketContext context) 14 { 15 WebSocket socket = context.WebSocket; 16 while (true) 17 { 18 ArraySegment<byte> buffer = new ArraySegment<byte>(new byte[1024]); 19 WebSocketReceiveResult result = await socket.ReceiveAsync( 20 buffer, CancellationToken.None); 21 if (socket.State == WebSocketState.Open) 22 { 23 string userMessage = Encoding.UTF8.GetString( 24 buffer.Array, 0, result.Count); 25 userMessage = "You sent: " + userMessage + " at " + 26 DateTime.Now.ToLongTimeString(); 27 buffer = new ArraySegment<byte>( 28 Encoding.UTF8.GetBytes(userMessage)); 29 await socket.SendAsync( 30 buffer, WebSocketMessageType.Text, true, CancellationToken.None); 31 } 32 else 33 { 34 break; 35 } 36 } 37 } 38 }
配置web.config
<system.webServer> <handlers> <add path="/WSChat/WSHandler.ashx" verb="*" name="WSHandler" type="WSChat.WSHandler"/> </handlers> </system.webServer>
html为:
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>WebSocket Chat</title> 5 <script type="text/javascript" src="Scripts/jquery-2.0.2.js"></script> 6 <script type="text/javascript"> 7 var ws; 8 $().ready(function () { 9 $("#btnConnect").click(function () { 10 $("#spanStatus").text("connecting"); 11 ws = new WebSocket("ws://" + window.location.hostname + 12 "/WSChat/WSHandler.ashx"); 13 ws.onopen = function () { 14 $("#spanStatus").text("connected"); 15 }; 16 ws.onmessage = function (evt) { 17 $("#spanStatus").text(evt.data); 18 }; 19 ws.onerror = function (evt) { 20 $("#spanStatus").text(evt.message); 21 }; 22 ws.onclose = function () { 23 $("#spanStatus").text("disconnected"); 24 }; 25 }); 26 $("#btnSend").click(function () { 27 if (ws.readyState == WebSocket.OPEN) { 28 ws.send($("#textInput").val()); 29 } 30 else { 31 $("#spanStatus").text("Connection is closed"); 32 } 33 }); 34 $("#btnDisconnect").click(function () { 35 ws.close(); 36 }); 37 }); 38 </script> 39 </head> 40 <body> 41 <input type="button" value="Connect" id="btnConnect" /> 42 <input type="button" value="Disconnect" id="btnDisconnect" /><br /> 43 <input type="text" id="textInput" /> 44 <input type="button" value="Send" id="btnSend" /><br /> 45 <span id="spanStatus">(display)</span> 46 </body> 47 </html>
context.IsWebSocketRequest 始终是False,请问怎么解决