简体   繁体   中英

escaping URL request? ASP.NET C#

I have a request to a page that looks like /doSomthing?a=that&ret=url however now i need to login so i must do something like /login?ret=/doSomthing?a=that&ret=url This doesnt work as well as one may hope so how do i correctly escape the return URL then unescape it?

I am using ASP.NET with C#

您应该对querystring部分进行URL编码,这可以使用HttpUtility类的UrlEncode方法完成:

 HttpUtility.UrlEncode(yourString);

You can do that by passing the target url through the UrlEncode method in the HttpServerUtility class. Example use, within a Page class:

string urlEncoded = Server.UrlEncode(this.Request.RawUrl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM