locked
There is no Web RRS feed

  • Question

  • Hi,

    I have written custom HTTP handler to redirect SharePoint sites using code below. I am using web property to store redirection url. The handler works perfect for all the requests except requests which has "_layouts/" in it. I am getting error on this line: 

    using (SPWeb objWeb = objSite.OpenWeb(SPContext.Current.Web.ID))
    And the error is : There is no web named.

    sample url: http://mysite.com/ABC/A/_layouts/settings.aspx

    I am using managed paths for site collections.

     1: try
     2:           {
     3:               using (SPSite objSite = new SPSite(Request.Url.AbsoluteUri))
     4:               {
     5:                  using (SPWeb objWeb = objSite.OpenWeb(SPContext.Current.Web.ID))
                        {
    
                            try
                            {
                                if (objWeb.Properties != null && objWeb.Properties.Count > 0)
                                {
                                    if (objWeb.Properties.ContainsKey("redirectionURL"))
                                    {
                                        Response.Redirect(objWeb.Properties["redirectionURL"].ToString());
    
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
    
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
    
                }


      
    Friday, October 13, 2017 11:42 AM

Answers

  • This is fixed by making below changes:

    using (SPWeb objWeb = objSite.OpenWeb())

    • Marked as answer by Kodnil Saturday, October 14, 2017 6:38 PM
    Saturday, October 14, 2017 6:38 PM