How to remove returnurl from url?

前端 未结 10 710
梦谈多话
梦谈多话 2020-11-28 08:54

I want to remove \"returnurl=/blabla\" from address bar when a user want to access to a login required page. Because I\'m trying to redirect the user to a static page after

10条回答
  •  误落风尘
    2020-11-28 09:10

    Add this to your Global.asax file.

    public class MvcApplication : HttpApplication {
    
      private const String ReturnUrlRegexPattern = @"\?ReturnUrl=.*$";
    
      public MvcApplication() {
    
        PreSendRequestHeaders += MvcApplicationOnPreSendRequestHeaders;
    
      }
    
      private void MvcApplicationOnPreSendRequestHeaders( object sender, EventArgs e ) {
    
        String redirectUrl = Response.RedirectLocation;
    
        if ( String.IsNullOrEmpty(redirectUrl) 
             || !Regex.IsMatch( redirectUrl, ReturnUrlRegexPattern ) ) {
    
          return;
    
        }
    
        Response.RedirectLocation = Regex.Replace( redirectUrl, 
                                                   ReturnUrlRegexPattern, 
                                                   String.Empty );
    
      }
    

提交回复
热议问题