我希望能够在WebMethod函数中获取当前经过身份验证的会话的SessionID,其中EnableSession = false.
我无法在此请求上设置EnableSession = true,因为另一个页面上的另一个(长时间运行的)请求会使SessionState保持锁定状态(EnableSessionState =="True"而不是"Readonly").
是否有一致的方法从ASP.NET会话cookie或Url获取SessionID用于无cookie会话?我可以自己编写代码,但我宁愿使用已经记录和测试过的函数.
非常感谢,
弗罗林.
我正在尝试简化将数据从WebMethod层返回到客户端的过程,并表示来自客户端的参数集,Dictionary<string,string>以执行以下操作:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static override ResultObject<List<PatientInfo>> GetResults(Dictionary<string, string> query)
{
ResultObject<List<PatientInfo>> resultObject = null;
if (!query.ContainsKey("finValue"))
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter from the query");
}
string finValue = query["finValue"];
if(finValue == null)
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter value from the query");
}
var patientData = GetPatientsByFin(finValue);
resultObject = new ResultObject<List<PatientInfo>>(patientData);
return resultObject;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何传递和反序列化Dictionary参数?
如何WebMethod从Windows应用程序在ASP.NET中调用它?
我尝试过使用web request post方法,但它返回了ASP.NET页面的XML.
这是我的网络方法:
[WebMethod()]
public static string Senddata(string value)
{
return "datareceived" + value;
}
Run Code Online (Sandbox Code Playgroud) 我得到的错误就像
非静态字段,方法或属性'System.Web.UI.Page.Session.get'需要对象引用
你能建议我在会话中从这个问题中恢复吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.SessionState;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//Onclick Submit Button
[WebMethod(EnableSession = true)]
//[System.Web.Services.WebMethod(EnableSession = true)]
public static string Login(string email, string password)
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["blogConnString"].ConnectionString);
con.Open();
string res = "0";
SqlDataReader reader;
string sql = "select uid,username from personal where email='" + email + "' …Run Code Online (Sandbox Code Playgroud) 这很奇怪。javascript 文件中的 onSuccess() 函数返回整个网页的大量HTML 代码,而不是我实际从 C# WebMethod 返回的值
1) 我在 Windows 10 上运行 Visual Studio 2015
2) 调试时,我在 SignupAccount C# 方法处保留了一个断点。断点没有被击中。还没有到那个地步。但是调用了 onSuccess 函数
这是一个解释:
ASP.NET Web 表单的 HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<!--Code-->
</head>
<body class="account2 signup" data-page="signup">
<!--Code-->
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<input type="text" name="firstname" id="firstname" placeholder="First Name" required autofocus>
<input type="text" name="lastname" id="lastname" placeholder="Last Name" required autofocus>
<button type="submit" onclick="signup()" id="submit-form" class="btn btn-lg btn-dark btn-rounded" data-style="expand-left">Sign In</button>
<script src="JS/Account.js"></script>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
C# …
好的,所以到目前为止我的网站一直在正常工作,我不确定我改变了什么.我有一个jQuery AJAX调用,它将优惠券代码发送到服务器,并检索一个数字(这是折扣).
Webmethod不再被解雇,而是正在触发webmethod所在页面的Page_load.为什么?我能检查什么?我能做什么?
这是我点击按钮时的处理程序
$('div#code_apply_btn').click(function() {
$(this).html('PLEASE WAIT');
getpromocode();
});
Run Code Online (Sandbox Code Playgroud)
这是AJAX调用
function getpromocode(){
var pcode = $('input#input_circuitcode').val();
var hid = parseInt($('input#ss_id_h').val());
$.ajax({
type: "POST",
url: "register.aspx/get_promocode",
data: '{"promo":"' + pcode + '", "uid":' + hid + '}',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (msg) {
if (msg.d != -1) {
applydiscount(msg.d);
$('div#reg_circuit').show();
$('div#circuit_promo').hide();
$('div#reg_circuit').click();
}
else {
$('input#input_circuitcode').val('');
$('div#code_apply_btn').html('APPLY CODE');
}
},
error: function (msg) {
alert(msg);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是网络方法
[WebMethod]
public static int get_promocode(string promo, int uid) …Run Code Online (Sandbox Code Playgroud) 我一直在网上搜索几个小时试图使用JQUERY $ .ajax将参数传递给我的代码.我尝试了很多不同的东西,但没有任何效果.当我没有传递任何参数并将vb.net函数设置为不接收参数时,函数将被调用.但是一旦我尝试添加参数,函数永远不会被调用.
客户端:
$("#<%=saveResource2.clientID %>").click(function() {
var parDesc = $("#<%=ddlPDesc.clientID %> option:selected").text();
$("#<%=Button1.clientID %>").click();
$.ajax({
type: "POST",
url: "Projects.aspx/btnSaveResource",
data: JSON.stringify({Desc: parDesc}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#<%=lblPerson.clientID %>").text(msg);
// Do something interesting here.
}
});
});
Run Code Online (Sandbox Code Playgroud)
服务器端:
Run Code Online (Sandbox Code Playgroud)<WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ Public Shared Function btnSaveResource(ByVal parDesc As String) As String Dim d As String = parDesc Return d + "test" End Function
我在Asp.net中使用X-Editable插件.
我试过这个:使用.Net和C#Webmethods
但它给了我错误.它没有像应该的那样调用WebMethod.
如何解决这个问题呢?
请帮忙.
使用Javascript:
$('#username').editable({
url: function (params) {
return $.ajax({
url: 'Default.aspx/TestMethod',
data: JSON.stringify(params),
dataType: 'json',
async: true,
cache: false,
timeout: 10000,
success: function (response) {
alert("Success");
},
error: function () {
alert("Error in Ajax");
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<a href="#" id="username" class="myeditable">superuser</a>
Run Code Online (Sandbox Code Playgroud)
Default.aspx中的WebMethod:
[System.Web.Services.WebMethod]
public static String TestMethod(String params)
{
//access params here
}
Run Code Online (Sandbox Code Playgroud) 我有静态方法,我想提取querystring请求的值.但是null当我从中调用它时,它给了我价值webmethod.下面是一些代码
public static int GetLatestAssetId()
{
int itemid=0;
if (HttpContext.Current.Request.QueryString["itemId"] != null)
itemid = Convert.ToInt32(HttpContext.Current.Request.QueryString["itemId"]);
return itemid;
}
[WebMethod]
public static string GetContactData()
{
GetLatestAssetId();
return "Success"
}
Run Code Online (Sandbox Code Playgroud)
我从ajax调用中调用这个web 方法.它在页面加载中工作正常但在静态方法中没有.我如何在静态方法中使用它.请协助.
我想将多个参数传递给我的ajax代码.哪个是3参数.所以,我添加如下
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("#txt712").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "FrmAgreementMaster.aspx/GetAutoCompleteData",
//data: "{'username':'" + extractLast(request.term) + "'}",
data: JSON.stringify("{'username':'" + extractLast(request.term) + "'}", "{'taluka':'" + document.getElementById('ddlTaluka').value + "'}", "{'village':'" + document.getElementById('ddlVillage').value + "'}"),
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
},
focus: function () {
return false;
},
select: function (event, ui) {
var terms = …Run Code Online (Sandbox Code Playgroud) webmethod ×10
asp.net ×7
jquery ×5
c# ×4
ajax ×2
javascript ×2
pagemethods ×2
.net ×1
json ×1
session ×1
sessionid ×1
vb.net ×1
web-services ×1