Forum Discussion
Custom Security Extension using Forms Authentication sending invalid URI on redirect
- 1 year ago
I figured out a solution. It's more of a workaround though.
I learned, without any specific details, that Windows Server 2022 datacenter has much more restrictive policies around URL validation and allowable query strings. My custom extension only needs the query string in order to determine where to redirect the user back to PowerBI once they are authenticated. Instead of trying to capture this in my Page_Load method, I moved that code to the OnInit method at the very beginning. I first check for the ReturnUrl parameter and if present I capture the url parameter from it into a cookie and then immediately redirect to my Logon.aspx page again without any query string.
Here's an example of the code:
override protected void OnInit(EventArgs e)
{
var uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
var returnUrl = HttpUtility.ParseQueryString(uri.Query).Get("ReturnUrl");
if (returnUrl != null)
{
var returnUri = new Uri("https://dummy.com" + returnUrl);
var encodedRedirectUrl = returnUri != null ? HttpUtility.ParseQueryString(returnUri.Query).Get("url") : null;
var decodedRedirectUrl = encodedRedirectUrl != null ? HttpUtility.UrlDecode(encodedRedirectUrl) : null;
if (decodedRedirectUrl != null)
{
var redirectUrlCookie = new HttpCookie("redirectUrl", decodedRedirectUrl)
{
HttpOnly = true,
Secure = true
};
Response.Cookies.Add(redirectUrlCookie);
}
string urlWithoutQueryString = uri.GetLeftPart(UriPartial.Path);
HttpContext.Current.Response.Redirect(urlWithoutQueryString);
}InitializeComponent();
base.OnInit(e);
}This manages to remove the query string from the URL that PowerBI is providing before the Windows Server 2022 restrictions apply to it.
Now my custom extension works on both Windows Server 2019 and 2022.
Hi abeckham7305,
Thank you for reaching out to Microsoft Fabric Community Forum.
Can you please check if the Windows Server 2022 environment has a different version of .NET installed compared to the Dev environment. Sometimes, different .NET versions handle URL encoding differently, which could be causing the issue.
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Regards,
Vinay Pabbu
- abeckham73051 year agoRegular Visitor
Thanks for the suggestion Vinay!
I checked the versions of .NET Framework, which is needed to run PowerBI, and they match across both servers. Both are using 4.8.
I don't know if it matters, but the dev server that works has both .NET 6 Core and .NET 8 Core installed on it. The 'Prod' server only has .NET 8 Core. I've been focusing mainly on .NET Framework because of PowerBI.
Do you think the .NET Core versions could matter for this?