question

Shri-6058 avatar image
0 Votes"
Shri-6058 asked Shri-6058 commented

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

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 http*s*://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


office-sharepoint-server-administrationoffice-sharepoint-server-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JulieWang-MSFT avatar image
0 Votes"
JulieWang-MSFT answered Shri-6058 commented

@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://docs.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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Solution I applied was to add "appendQueryString="false"" and works like a charm!

0 Votes 0 ·
sadomovalex avatar image
0 Votes"
sadomovalex answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.