简体   繁体   English

我想将用户名和密码从html文件传递到(webservice)asmx文件。 我应该使用什么?

[英]I want to pass the username and password from html file to (webservice )asmx file. what should i use?

<form class="login" id="frmLogIn" method="post" runat="server">
    <p class="title"><i class="fa fa-user-o" style="font-size:20px;color:brown"></i> Log in </p>
      <input type="text" placeholder="Username" id="txtusername" runat="server"/>
    <i class="fa fa-user"></i>
   <input type="password" placeholder="Password" id="txtpassword"runat="server"/>
    <i class="fa fa-key"></i>

    <a href="#">Forgot your password?</a>
    <button>
      <i class="spinner"></i>
      <span class="state" id="btnLogIn" runat="server" onclick="btnLogIn_Click">Log in</span>

    </button>

  </form>

I want to pass the username and password from html file to (webservice )file.but i don't know how because i'm newbie to asp.net. 我想将用户名和密码从html文件传递到(webservice)file。但是我不知道怎么做,因为我是asp.net的新手。 If i sink the html into the asp file the html interface will change. 如果我将html下沉到asp文件中,则html界面将更改。 i want to use c-sharp for back end what should i use?. 我想将c-sharp用于后端我应该使用什么?

Your html file 您的html文件

 $(document).ready(function () {
            var validateUsername = $('#validateUsername');
            $('#username').keyup(function () {
                var t = this;
                if (this.value != this.lastValue) {
                    if (this.timer) clearTimeout(this.timer);
                    validateUsername.removeClass('error').html('<img src="images/ajax-loader.gif" height="16" width="16" /> checking availability...');
                    this.timer = setTimeout(function () {
                        $.ajax({
                            contentType: "application/json; charset=utf-8",
                            url: 'ValidateUser.asmx/GetUsernameAvailable',
                            data: '{username: "'+t.value + '"}',
                            dataType: 'json',
                            type: "post",
                            success: function (j) {
                                validateUsername.html('I willl have my logic in here for changing the html on the label to reflect success or failure!');
                            }
                        });
                    }, 200);

                    this.lastValue = this.value;

Asmx File Asmx文件

<%@ WebService Language="C#" Class="ValidateUser" %>
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.Odbc;
using System.Web.Script.Serialization;
using System.Web.Script.Services; 
using UserSite.DataClasses;

[WebService(Description = "Web services to query Username availability.", Namespace = "http://localhost")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ValidateUser: System.Web.Services.WebService
{

    [WebMethod(Description = "Gets the availability of a username.")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetUsernameAvailable(string username)
    {

        if (username == null)
        {
            username = "";
        }
        DbaseExecSpWithReturnValue Sproc = new DbaseExecSpWithReturnValue();
        Sproc.SetSp("sp_CheckUsernameAvailable");
        Sproc.AddParam(1);
        Sproc.AddParam("Username", SqlDbType.Char, username, 20);
        int RetVal = Sproc.Execute();
        Sproc.Close();
        if (RetVal == 0)
        {
            return @"{""available"": false}";
        }
        else
        {
            return @"{""available"": true}";
        }

    }
}


public bool GetUsernameAvailable(string username)
{
   ...
   return (RetVal == 0) ? false : true;
}

Ajax Above would return boolean value and you call access it in your call function as jd For example, Ajax Above将返回布尔值,您可以在调用函数中以jd的形式调用access,例如,

...
$ajax({
 ...
 success: function (j) {
    alert(j.d); // will alert either true or false
 }
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过代码模拟Web服务文件(asmx)? - How can I impersonate a webservice file (asmx) from code? 对于非.net客户端要使用的asmx Web服务,应使用哪种值类型列表? - What list of values type should I use for an asmx webservice to be consumed by non .net clients? 我能够将用户名和密码传递给Web服务,但这不是我需要防止未经授权的用户访问的方式 - I was able to pass username and password to webservice, but its not the way i need to secure from unauthorized user 我从asmx Web服务获得了XML文件,如何将其绑定到Windows窗体的gridview中? - I got an XML file from asmx webservice, how do I bind it in the gridview of my windows form? Silverlight 5-从WebService asmx下载zip文件 - Silverlight 5 - Downloading a zip File from WebService asmx 来自类型的新对象? 特别是一个resx文件。 我在运行时需要一个不同的resx - New object from type? Specifically a resx file. I want a different resx at runtime 需要在c#中使用asmx webservice(wsdl)来更新和删除这个xml文件 - need to use an asmx webservice(wsdl) in c# to update and delete from this xml file 如何从链接(ftp)下载zip文件并传递用户名和密码? - How to download a zip file from link (ftp) and pass username and password? 我将如何从文本文件中读取我的球员和武器位置。 我想要游戏开始自动加载时 - How would I read my player and weapons positions from a text file. I want when the game starts to automatically load them in 如何从ASMX Webservice返回用户定义的对象 - How can I return a user defined object from ASMX Webservice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM