How to elegantly handle ReturnUrl when using UrlRewrite in ASP.NET 2.0 WebForms

前端 未结 4 1720
情歌与酒
情歌与酒 2021-01-13 03:12

I have a folder with multiple .aspx pages that I want to restrict access to. I have added web.config to that folder with .

The

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 03:31

    Check it out. Hope this helps.

    #region [ Imports ]
    
    using System;
    using System.Web;
    using System.Web.Security;
    
    #endregion
    
    namespace Foo.Handlers
    {
    
        public class AuthModule : IHttpModule
        {
    
            #region IHttpModule Members
    
            public void Init(HttpApplication application)
            {
                application.PostReleaseRequestState += delegate(object s, EventArgs e)
                    {
                        if (application.Response.StatusCode == 401)
                            application.Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + HttpUtility.UrlEncode(application.Request.RawUrl), true);
                    };
            }
    
            public void Dispose() { }
    
            #endregion
    
        }
    
    }
    

    
      
    
    

提交回复
热议问题