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 =