My IIS server link is like h t t p s://iis/myApp
I have a redirect in Index. a s p x which is in the root folder
C#
protected void Test_RedirectSSM(object sender, EventArgs e)
{
Response.Redirect("~/UserPages/TestareSSM. a s p x");
}but on btn click the path become
h t t p s://iis/UserPages/Testare SSM. a s p x, ignoring the root folder myApp
I tried with full path on Response.Redirect
C#
protected void Test_RedirectSSM(object sender, EventArgs e)
{
Response.Redirect("h t t p s:/iis/myApp/UserPages/ TestareSSM . a s p x");
}but it still ignores myApp. Please help me fix this


Aman GuptaRank #193 · 12.4K reputationPosted Aug 22, 2024, 1:26 PM EDT
Hi Marius,
The issue you're encountering with
Response.Redirectnot correctly including themyApproot folder in the URL is likely due to how the path is being resolved in the IIS environment. Here's how you can fix it:1. Use
ResolveUrlin code>Response.Redirect:ResolveUrlhelps in resolving the correct path based on the application root, ensuring that themyAppfolder is included in the URL.protected void Test_RedirectSSM(object sender, EventArgs e) { string url = ResolveUrl("~/UserPages/TestareSSM.aspx"); Response.Redirect(url); }2. Use
Request.ApplicationPath:Another approach is to manually build the URL using
Request.ApplicationPath, which will ensure that the application’s root folder (myApp) is correctly prefixed in the URL.protected void Test_RedirectSSM(object sender, EventArgs e) { string url = $"{Request.ApplicationPath}/UserPages/TestareSSM.aspx"; Response.Redirect(url); }3. Absolute Path:
If you are dealing with a situation where you must use an absolute path, ensure you correctly structure it, including the full application path:
protected void Test_RedirectSSM(object sender, EventArgs e) { Response.Redirect("https://iis/myApp/UserPages/TestareSSM.aspx"); }ResolveUrl("~/...")is often the most reliable and easiest way to ensure URLs are correctly resolved relative to the application root.Request.ApplicationPathcan be used to dynamically construct paths based on where your application is deployed.myAppportion.These approaches should help ensure that the redirect URL correctly includes your application's root folder (
myApp) when deploying on IIS.Marius VasileRank #785 · 2.9K reputationPosted Aug 23, 2024, 12:53 AM EDT
Thank you Aman,
I tried all three options and I have the same result, the root folder is considered without myApp
Other redirections, ex. to Index works fine but this one