hiboss hiboss - 14 days ago 6
ASP.NET (C#) Question

How to redirect page for unauthorized user

I having a asp.net program that i can only configure with web.config file.
Having this code below, it could help me redirect to login page.

<authentication mode="Forms">
<forms name="ZukamiLogin" path="/" loginUrl="login.aspx" protection="All" slidingExpiration="true" />
</authentication>
<authorization>
<deny users="?" />


However, when i changed the loginUrl to "login.aspx?AppID=90441b68-3515-4fdd-851a-4a2b753e5557&anonyform=2f7fbed9-3ef4-4e9d-b164-0f4b6104cf78" , it shows me error. Is there any way to redirect user to this link instead of login.aspx?

Edit :
added with image for the error
enter image description here

Answer

You can't have special characters ?, =, or . in tags or attributes because they are special characters in XML. You have to use their numeric character reference.

So:

loginUrl="login.aspx&#63;AppID&#6190441b68&#45;3515&#45;4fdd&#45;851a&#45;4a2b753e5557&#38;anonyform&#612f7fbed9&#45;3ef4&#45;4e9d&#45;b164&#45;0f4b6104cf78"

(you might want to check my typing)

This has the whole table of character references: https://www.dvteclipse.com/documentation/svlinter/How_to_use_special_characters_in_XML.3F.html#gsc.tab=0

Edit: Apparently for URLs it's better to use a different character encoding scheme (URL-encode) explained in the accepted answer here: Android: How store url in string.xml resource file?