Use JSONP to log on to the WEB system in ASP. NET MVC3

Source: Internet
Author: User
Tags oauth

During information system development, multiple systems may log on to each other based on the relevant business logic. In general, we need to use multiple user names and passwords between multiple systems. In this way, the customer needs to log on to multiple systems repeatedly. Enter the user name and password for each login. Recently, OAuth is popular. Sina Weibo is doing well in this open system. However, OAuth is not covered in this article. Here we mainly discuss the application of jQuery1.5 jsonp in Asp.net MVC3.

Application scenarios:

Assume that your development team wants to develop a complete information management system for a group company. At present, the first development is an order system and an internal OA system. The premise is that the two systems use the same database. There are only two different MVC3.0 Web projects. That is to say, two virtual directories will be deployed on the same IIS. Our goal is to achieve cross-origin login without using technologies such as WCF and WebService. That is to say, if you use the same account to log on to the Order System, the customer can directly log on to the OA system. You do not need to enter the user name and password again on the OA system. And vice versa.

Use jQuery1.5 JSONP:

<Script type="Text/javascript">
2$ (Function(){
3 VarOAUri= "@ ViewBag. OAVRUri";
4 VarUser= "@ ViewBag. User";
5 VarPwd= "@ ViewBag. PassWord";
6
7$. Ajax ({
8Type:"GET",
9Url: String. format ({0} Account/AppLogOn? UserName = {1} & PassWord = {2} & callback =?,OAUri, user, pwd ),
10Cache:False,
11Error:Function(){
12Alert ("Program error. Contact the administrator.");
13},
14DataType:"Jsonp",
15Jsonp:Callback,
16Success:Function(Result ){
17
18}
19});
20
21});
22 </Script>


  Create a JSONP dedicated ActionResult in MVC3.0

The Code is as follows:

 1 public class JsonpResult<T> : ActionResult
2 {
3 public T Obj { get; set; }
4 public string CallbackName { get; set; }
5
6 public JsonpResult(T obj, string callback)
7 {
8 this.Obj = obj;
9 this.CallbackName =
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.