How to determine .NET cookie path

不羁岁月 提交于 2019-12-22 18:38:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!