2011-02-02 77 views
0

我有一个网站托管在安装了URL Rewrite module 2.0的IIS 7上。它由内容管理系统运行,查看URL并在当前用户无权查看页面时返回401错误。这被ASP.NET URL授权模块接收,然后按照web.config文件(表单身份验证)中指定的方式将页面踢到loginUrl页面。具有URL重写模块2.0的IIS 7 - 设置401状态代码和ReturnUrl

这工作完全在我的本地机器上 - 这是IIS 7和Windows 7

如果URL,比如,/612/some-string用户获取对/66/login?ReturnUrl=/612/some-string定向到登录页面。

URL重写将查看文档ID的URL的第一部分。真正的URL是这样的:index.aspx?documentId=612

不幸的是,当我将它部署到我们的登台服务器时,ReturnUrl不是重写的URL,而是原始URL。这会导致各种问题。

登台服务器也是安装了URL Rewrite Module 2.0的IIS 7。它是Windows 2008服务器SP2。两者都运行ASP.NET 3.5。

我唯一的猜测是machine.config文件以不同的方式排列默认的httpModules,.NET表单验证模块在URL被重写之前跳入。

我会尽快审查,但在此期间,这个问题的经验是什么,它可以解决?

更新

我也试图改变

Response.StatusCode = 401; 

FormsAuthentication.RedirectToLoginPage(); 

这让我有点超前,但还是引导用户回到那个已经不是网址被重写。

我也能做到这一点,而不是设置了401:

string currentPage = HttpUtility.UrlEncode(Request.RawUrl); 
string loginUrl = FormsAuthentication.LoginUrl + "?ReturnUrl=" + currentPage; 
Response.Redirect(loginUrl); 

但这似乎难看。

+0

任何决议对此? – iambriansreed 2013-06-20 13:36:43

回答

1

在本书多米尼克·拜尔开发更多=安全的Microsoft ASP.NET 2.0应用程序的第二章有一个ShowPipeline.ashx表示采用一个HttpHandler在服务器上完成管道排序:

<%@ WebHandler Class='ShowPipeline' Language='c#' %> 

    using System; 
    using System.Web; 
    using System.Reflection; 
    using System.ComponentModel; 

    // shows which modules have registered for which event 
    // add a ?asm=true query string parameter to also show the assemblies 
    public class ShowPipeline : IHttpHandler 

    { 
     static bool _showAssemblies = false; 

     // names of the pipeline events 
    static string[] _handlerNames = { 
     "BeginRequest", 
     "AuthenticateRequest", 
     "DefaultAuthentication", 
     "PostAuthenticateRequest", 
     "AuthorizeRequest", 
     "PostAuthorizeRequest", 
     "ResolveRequestCache", 
     "PostResolveRequestCache", 
     "AcquireRequestState", 
     "PostAcquireRequestState", 
     "PreRequestHandlerExecute", 
     "PostRequestHandlerExecute", 
     "ReleaseRequestState", 
     "UpdateRequestCache", 
     "PostUpdateRequestCache", 
     "EndRequest" 
    }; 

    public void ProcessRequest(HttpContext ctx) 
    { 
     if (ctx.Request.QueryString["asm"] == "true") 
      _showAssemblies = true; 

     ctx.Response.Write("<hr>"); 

     foreach (string s in _handlerNames) 
     { 
      _showHandlers(s); 
     } 

     ctx.Response.Write("<hr>"); 
    } 

    public void _showHandlers(string handlerName) 
    { 
     HttpResponse r = HttpContext.Current.Response; 
     object key = _getPrivateAppField("Event" + handlerName); 
     EventHandlerList ehl = (EventHandlerList)_getPrivateAppField("_events"); 
     MulticastDelegate md = (MulticastDelegate)ehl[key]; 
     if (null != md) 
     { 
      r.Output.WriteLine("<h2>{0}</h2>", handlerName); 
      foreach (Delegate d in md.GetInvocationList()) 
      { 
       Type tt = d.Target.GetType(); 
       string asm = ""; 
       if (_showAssemblies) 
       { 
        asm = string.Format("<font color='red'>[{0}]</font>", tt.Assembly.GetName()); 
       } 
       r.Output.WriteLine("{0}{1}.<font color='blue'>{2}</font><br>", asm, tt, d.Method.Name); 
      } 
     } 
    } 
    object _getPrivateAppField(string fieldName) 
    { 
     return _getPrivateField(typeof(HttpApplication), fieldName, HttpContext.Current.ApplicationInstance); 
    } 

    object _getPrivateField(Type t, string fieldName, object o) 
    { 
     return t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).GetValue(o); 
    } 

    object _getPrivateField(string fieldName, object o) 
    { 
     return o.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic).GetValue(o); 
    } 

    public bool IsReusable { get { return true; } } 
} 
+0

我喜欢它。对解决问题不太有用,但我喜欢这个。 – RoLYroLLs 2012-12-12 03:28:46