Asp.net WebService security verification

Source: Internet
Author: User

 

WebService, cross-platform, standardized, and other advantages over a period of time are not mentioned, but there are also many disadvantages.

Especially for security issues, as long as you know that the WebService address can be accessed through the Asp.net Web Service, and the methods are explicit, it is not safe.

Today, we have added the Security Authentication Mechanism to WebService, so that we have a level-1 verification.

 

For example:

Create a WebService

 
Public class WebService: system. web. services. webService {Public Key key = new key (); Public WebService () {// if you are using the designed component, uncomment the following line // initializecomponent ();} [webmethod] [soapheader ("key")] Public String helloworld () {If (key. isvalid () Return "Hello World"; else return "";}}

Create an operation key that inherits the soapheader

Public class key: soapheader {Public Key () {// todo: add the constructor logic here // security key public string key {Get; set ;} public bool isvalid () {return isvalid (key);} public bool isvalid (string key) {try {string keyconfig = "123"; if (Key = keyconfig) {return true;} else {return false ;}} catch {return false ;}}}

Call:

 
WebService. webService webs = new WebService. webService (); WebService. key key = new WebService. key (); key. key = "123"; webs. gnet_keyvalue = key; show. innerhtml = webs. helloworld ();

If the key is incorrect, null is returned; otherwise, helloworld is returned.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.