Problem executing order of SPContext.Current.Web.Url and IIS rewrite url to https

Shri-6058 326 Reputation points
2021-09-13T03:55:54.503+00:00

Hi

I have an http:// SharePoint web application. I have also hosted webparts and created IIS folder to launch application such as http://myCompany.portal.com/empDashboard and It loads every employee current login and display dashboard all employee activities and projects. I also have an adminview and if I pass parameter like http://myCompany.portal.com/empDashboard/?adminview=<empCode>, I can load the application for others(this is secured and only for me to support). All functionalities are working just fine. I was asked to upgrade the SP farm web application to https:// and hence I configured the certificate. I am able to run entire web application and also updated the redirect <rewrite></rewrite> in IIS. All working just fine except the impersination(admin view) part.

when I access http://myCompany.portal.com/empDashboard its automatically redirect to https://myCompany.portal.com/empDashboard however when I impersinate other employee, http://myCompany.portal.com/empDashboard/?adminview=<empCode> it changes as https://myCompany.portal.com/empDashboard/?adminview=<empCode> and then throws error stating cannot be null. It is very strange that if I directly access https://myCompany.portal.com/empDashboard/?adminview=<empCode> works just fine. It looks like IIS redirect is executed after this "SPContext.Current.Web.Url" causing value cannot found or address doesnt exist error. How can I ensure that redirect url executes first and then SPContent read the url?

Please advise. Appreicate any help.

Shri

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,227 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,811 questions
0 comments No comments
{count} votes

Accepted answer
  1. JoyZ 18,041 Reputation points
    2021-09-13T09:10:15.387+00:00

    @Shri-6058 ,

    Please check if you add the following option under rewrite action:

    <action type="Redirect" url="xxxx" appendQueryString="false" redirectType="Found" />

    Simialr issue for your reference:

    https://forums.iis.net/t/1201692.aspx?IIS+URL+Rewrite+with+Query+String+on+SharePoint+Application

    More information about URL Rewrite Module Configuration Reference:

    https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#using-back-references-in-rewrite-rules


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. sadomovalex 3,626 Reputation points
    2021-09-13T14:53:47.467+00:00

    it doesn't answer question but IIS redirection happens before SPContext.Current.Web is initialized. SPContext.Current.Web is set in Sharepoint's HTTP module which is listed in web.config of your SP app's virtual folder. Under the hood it adds "HttpHandlerSPWeb" entry to HttpContext.Current.Items collection. Based on that you may even create fake SP context when needed - see Override SPContext.Current.Web and Site with sites opened with elevated privileges.

    0 comments No comments