ASP. NET MVC uses the WiFiDog protocol for WiFi authentication

Source: Internet
Author: User

Many of the WiFiDog protocols that I see on the internet are generally PHP, but I do understand PHP but prefer. NET, so that a simple login authentication function is implemented.

(Many of the features in the Protocol are not currently implemented.)

1. Development environment (VS2010)

2. Routing (DDWRT support for WiFiDog protocol)

3. Configuration of the environment

The main route is the configuration

As follows:

Note the red circle part of this I follow the configuration of PHP

The configuration of ASP. NET MVC is as follows:

Port 9999 Authserver path/login/

4. MVC Project layout:

The LoginController.cs code is as follows:

public class Logincontroller:controller
{
//
GET:/login/

Public ActionResult Login ()
{
String demo = Request.QueryString.ToString ();
viewdata["Demo"]=demo;
viewdata["gw_address"] = request.querystring["gw_address"];
viewdata["Gw_port"] = request.querystring["Gw_port"];
viewdata["gw_id"] = request.querystring["gw_id"];
viewdata["url"]=request.querystring["url"];
String url = request.querystring["url"];
String url = "Www.cnblogs.com";

viewdata["url"] = URL;
Response.Write ("Auth:1");
return View ();
}

Public ActionResult Index ()
{
return View ();
}

Public ActionResult Auth ()
{
Result data = new result ();

Response.Write ("Auth:1");
return View ();


}
Public ActionResult MyLogin ()
{

return View ();
}
}

The code is quite messy, but it's still relatively simple.

The code for login view is as follows:

<%
Label1.Text = viewdata["Demo"]. ToString () + "<br/>";

if (viewdata["url"] = = null)
{

}
Else
{
String a = viewdata["gw_address"]. ToString ();
String p = viewdata["Gw_port"]. ToString ();
String token = Guid.NewGuid (). ToString ();
String url=viewdata["url"]. ToString ();
String demo = "http://" + A + "" + + P + "/wifidog/auth?token=" + token + "url=" + url;

viewdata["AuthUrl"] = demo;
application["AuthUrl"] = demo;
}

%>

Dalong Demo App
<p>


Landing page
<asp:label id= "Label1" runat= "Server" text= "Label" ></asp:Label>
</p>

[<%: Html.ActionLink ("Enter", "MyLogin", "Login")%>]

The code for MyLogin view is as follows:

<%

String Tepdemo = "Auth:1";
byte[] data = System.Text.Encoding.Default.GetBytes (Tepdemo);
char[] List = System.Text.Encoding.Default.GetChars (data);
Response.Write (list, 0, list. Length);
Response.Redirect (application["AuthUrl"). ToString ());
%>

5. The test result of the mobile phone side:

Window phone to connect to the WiFi display screen

Click to enter the following effect:

Connection Success Flag:

To open a Web page:

The most important thing for authentication is the data returned by the protocol:

For example, I passed the data returned:

Auth:1

Rejected as: auth:0

The above is just a simple test, the actual application needs a lot of things.

ASP. NET MVC uses the WiFiDog protocol for WiFi authentication

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.