问题
I am writing a .NET application that uses cookies to store a login token. I'd like the user to be able to log into multiple installations of this application on the same server (let's say jacob.local/Devel
and jacob.local/Stable
), so I want to set the Path property for the cookies appropriately. Currently I'm using Request.ApplicationPath
but am running into trouble when the user visits the site with a different case than what I've set up in IIS.
For example, the user visits jacob.local/stable
-- the cookie's path will be /Stable
, which the browser doesn't send back to me since it can't know that IIS is case insensitive.
Do I have to parse apart the whole query string myself, or is there already a function for figuring out what the path of the application is?
回答1:
The following trick grabs the application path with casing matched to the one specified in the URL of the current request.
Request.Url.AbsolutePath.Remove(Request.ApplicationPath.Length)
来源:https://stackoverflow.com/questions/1412512/how-to-determine-net-cookie-path