//url encryption and decryption
string res1 = Httputility.urlencode ( " 7z2k5lgk/ii= " ); // string res2 = Httputility.urlencode (res1); // string res3 = Httputility.urldecode (res2); // string res4 = Httputility.urldecode (RES3);
//
usingGiftweb.dao;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text.RegularExpressions;usingsystem.web;usingSYSTEM.WEB.MVC;namespacegiftweb.controllers{ Public classLogincontroller:controller {// //GET:/login/ PublicActionResult Index () {//1. When the session expires automatically stringRETURNURL =Request.rawurl; stringURL =string. Empty; if(! Regex.IsMatch (RETURNURL,@"^/login/index") ) {URL=Httputility.urlencode (RETURNURL); } //gets the ULR address at exitURL = request["RETURNURL"]; Viewbag.returnurl=URL; returnView (); } [HttpPost] PublicActionResult Index (stringLoginNamestringpassword) { using(Giftdbentities db =Newgiftdbentities ()) { varUserInfo = db. Sysuserinfo.where (U = u.loginname = = LoginName && U.password = =password). FirstOrDefault (); if(UserInfo = =NULL) {viewbag.msg="logon name or password error"; returnView (); } Else { //gets the ULR address at exit stringURL = request["RETURNURL"]; //Decryption of URLs stringresult =httputility.urldecode (URL); session["SysUserInfo"] =UserInfo; if(string. IsNullOrEmpty (URL)) {returnRedirecttoaction ("Index","Topicinfo"); } Else { returnredirectpermanent (Result); } } } } PublicActionResult Logout () {//gets the current URL stringURL = request["RETURNURL"]; //Encrypt the URL stringresult =httputility.urlencode (URL); //let the session expireSession.Abandon (); //Jump to login page returnContent (Result); } }}
<Scripttype= "Text/javascript"> functionlogout () {varURL= "@Request. RawUrl"; alert (URL); $.post ("/login/logout?returnurl="+URL,function(data) {if(Data!= NULL) {window.location= "/login/index?returnurl=" +data; } }); } </Script>
The URL gets very simple, ASP. NET generic:
"1" get the full URL
(Protocol name + domain + virtual directory name + file name + parameter)
String url=request.url.tostring ();
"2" gets the virtual directory name + page name + parameters:
String Url=request.rawurl;
(or string
Url=request.url.pathandquery;)
"3" get
Virtual directory name + page name:
String Url=httpcontext.current.request.url.absolutepath;
(or
String url= HttpContext.Current.Request.Path;)
"4" gets the domain name:
String
Url=httpcontext.current.request.url.host;
"5" gets the parameter:
String url=
HttpContext.Current.Request.Url.Query;
"6" Gets the port:
Request.Url.Port
Ii. acquisition of the current Controller and action
RouteData.Route.GetRouteData (this. HttpContext). values["Controller"]
RouteData.Route.GetRouteData (this. HttpContext). Values["Action"]
or
routedata.values["Controller"]
routedata.values["Action"]
If you can use it in the view
ViewContext.RouteData.Route.GetRouteData (this. Context). values["Controller"]
ViewContext.RouteData.Route.GetRouteData (this. Context). Values["Action"]
or
viewcontext.routedata.values["Controller"]
viewcontext.routedata.values["Action"]
ASP. NET MVC URL App