none
SharePoint 2010 - HTTPModule with Server.Transfer gives error RRS feed

  • Question

  • Hi ,

    I have this requirement of rewriting Friendly URLs for a SharePoint web app to the original paths.

    I have a custom HTTPModule with a BeginRequest event. The module is registered in the <modules tag of the web.config.

    It works well with Response.Redirect but I am trying to use Server.Transfer since I want it to retain the requested URL.

    This gives an error -

    "This method can only be called after the authentication event."

     System.Web.HttpRequest.get_LogonUserIdentity() +207
       Microsoft.SharePoint.ApplicationRuntime.SPRequestModuleData.GetRequestData(HttpContext context, String virtualPath, Boolean allowCreate) +176
       Microsoft.SharePoint.ApplicationRuntime.SPVirtualFile.GetRequestData(HttpContext context, String virtualPath, Boolean allowCreate, Boolean throwOnNoRequestData) +22
       Microsoft.SharePoint.ApplicationRuntime.SPVirtualFile.GetVirtualPathProviderCacheKey(String virtualPath) +36
       Microsoft.SharePoint.ApplicationRuntime.SPVirtualPathProvider.GetCacheKey(String virtualPath) +67
       System.Web.Compilation.BuildManager.GetCacheKeyFromVirtualPath(VirtualPath virtualPath, Boolean& keyFromVPP) +38
       System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +82
       System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +116
       System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +175
       System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +52
       System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +50
       System.Web.HttpApplication.MapIntegratedHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig, Boolean convertNativeStaticFileModule) +644
       System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +947
    
    [HttpException (0x80004005): Error executing child request for /sites/TestMUI/SitePages/Home.aspx.]
    

    I tried a number of things like making my web app anonymous, changing the authentication mode in the web.config to "Windows", "None" etc. bbut in vain. Some how am not sure how to authenticate the request before the BeginRequest event.

    Here is my HTTModule code-

    using System;
    using System.Web;
    using System.Web.UI;
    using System.IO;
    using Microsoft.SharePoint;
    
    namespace CustomHTTPModule
    {
        public class MyModule1 : IHttpModule
        {
            /// <summary>
            /// You will need to configure this module in the web.config file of your
            /// web and register it with IIS before being able to use it. For more information
            /// see the following link: http://go.microsoft.com/?linkid=8101007
            /// </summary>
            #region IHttpModule Members
    
            public void Dispose()
            {
                //clean-up code here.
            }
    
            public void Init(HttpApplication context)
            {
                // Below is an example of how you can handle LogRequest event and provide 
                // custom logging implementation for it
               
                          
                context.BeginRequest += new EventHandler(context_BeginRequest);
                  
            }
    
            
    
            void context_BeginRequest(object sender, EventArgs e)
            {
                
               HttpApplication app = (HttpApplication)sender;
               HttpContext objContext = (HttpContext)app.Context;
    
                string requestUrl = app.Request.Url.ToString();
    
                
                           if (requestUrl.Contains("/sites/Home"))
                            {
                                
                               //objContext.Response.Redirect("/sites/TestMUI/SitePages/Home.aspx");
                                app.Server.Transfer("/sites/TestMUI/SitePages/Home.aspx");
     
                                                 }
                        
    
            }
    
            #endregion
    
           
        }
    }
    
    <modules runAllManagedModulesForAllRequests="true">
          <add name="CustomHTTPModule" preCondition="integratedMode" type="CustomHTTPModule.MyModule1, CustomHTTPModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9eec5e2ad94ff809" />

    Above is my web.config insert

    Any help will be appreciated

    Thanks

    AdiS

    

    Monday, February 13, 2012 4:25 AM

All replies

  • Can you try Server.TransferRequest

    Varun Malhotra
    =================
    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

    Monday, February 13, 2012 4:52 AM
  • Thanks. I tried Server.TransferRequest but now it keep prompting me for credentials.

    I keyed in my windows credentials but doesn't seem to work.

    I tried all <authentication modes in web.config  Forms,Windows, None. All prompt me for credentials.

    Any ideas?

    Thanks so much

    AdiS

    Monday, February 13, 2012 5:20 AM
  • Thanks. I tried Server.TransferRequest but now it keep prompting me for credentials.

    I keyed in my windows credentials but doesn't seem to work.

    I tried all <authentication modes in web.config  Forms,Windows, None. All prompt me for credentials.

    Any ideas?

    Thanks so much

    AdiS


    AdiS

    Monday, February 13, 2012 2:14 PM