如何确定.NET Cookie路径 [英] How to determine .NET cookie path

查看:177
本文介绍了如何确定.NET Cookie路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个使用Cookie来存储一个登录令牌.NET应用程序。我希望用户能够登录到同一台服务器上该应用程序的多个安装(比方说 jacob.local /杰韦利侨光。本地/稳定),所以我要设置适当的路径属性的cookie。目前我使用 Request.ApplicationPath ,但我遇到了麻烦,当用户访问一个不同的情况比我在IIS中设置的站点。

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.

例如,用户访问 jacob.local /稳定 - cookie的路径将是 /稳定,该浏览器不发回给我,因为它无法知道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?

推荐答案

下面的技巧抓住与外壳相匹配的当前请求的URL指定的应用程序的路径。

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)

这篇关于如何确定.NET Cookie路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆