我想在登录时设置一个用户时区的cookie.AccountController.LogOn()似乎是最好的地方.但是,我还不能在那里读取用户的配置文件,因为我猜你只能在方法完成时访问配置文件.所以,这段代码返回一个空字符串:
Dim timeZone = HttpContext.Profile("TZ").ToString
Run Code Online (Sandbox Code Playgroud)
用户完全登录后,上面的代码将返回正确的TimeZone.
一种解决方案是读取尝试在AccountController.LogOn()中登录的用户名的配置文件:
ProfileCommon profile = Profile.GetProfile(username); // FAILS
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.
那么,如果他们没有登录,我如何阅读给定用户的个人资料?
我看到MVC.NET的第2版现在有一个RequireHttps属性,这对我很有用.然而,什么是关闭效果的好策略?例如,我想在某些页面上使用Https,但在其他页面上使用常规Http.我应该创建自己的RequireHttp属性吗?
编辑:我使用自己的RequireHttp属性,它工作正常,但我想知道在MVC.NET版本2中是否有一些我缺少的内置功能.
编辑2:我一定不清楚.我的问题涉及以下内容:如果您使用RequireHttps,那么之后的任何请求都将超过Https,即使Controller或Action未使用RequireHttps进行修饰.除非我弄错了,否则你需要第二个属性,例如RequireHttp,将请求重定向到Http而不是Https.
我无法弄清楚这一点.我需要从FQDN中提取二级域.例如,所有这些都需要返回"example.com":
这是我到目前为止所拥有的:
Dim host = Request.Headers("Host")
Dim pattern As String = "(?<hostname>(\w+)).(?<domainname>(\w+.\w+))"
Dim theMatch = Regex.Match(host, pattern)
ViewData("Message") = "Domain is: " + theMatch.Groups("domainname").ToString
Run Code Online (Sandbox Code Playgroud)
它失败的example.com:8080和bar.foo.example.com:8080.有任何想法吗?
在VB.NET中,如何将以下字符串转换为某种键/值类型,如Hashtable,Dictionary等?
"Name=Fred;Birthday=19-June-1906;ID=12345"
Run Code Online (Sandbox Code Playgroud)
我想提取生日或ID,而不必将字符串拆分为数组.
编辑:如果字符串的格式稍后更改,我宁愿不将字符串拆分为数组.我无法控制字符串.如果有人切换订单或添加另一个元素怎么办?
想象一下这个受歧视的联盟:
type Direction =
| North
| South
| East
| West
Run Code Online (Sandbox Code Playgroud)
现在假设我想要一种只接受(北,南)或(东,西)元组的类型.也许这将描述仅从北向南或从东向西的火车路线.(北,东)和(南,西)应该是禁止的,也许是因为火车不像那样运行.
这不起作用:
type TrainLines =
| North, South
| East, West
Run Code Online (Sandbox Code Playgroud)
即使这不起作用,也许你可以看到我正在尝试做什么.
这有效,但不仅限于(北,南)和(东,西)的可能性:
type TrainLines = Direction * Direction
Run Code Online (Sandbox Code Playgroud)
任何指导都会受到欢迎.
我使用node-formidable通过POST处理表单http://127.0.0.1/upload.处理完毕后,我想将用户重定向到http://127.0.0.1/.目前,我需要重新加载http://127.0.0.1/才能看到上传的数据.我假设我需要调整缓存设置.
我怎么能在Node.js中这样做?我是否Cache-Control: no-cache开机http://127.0.0.1/或/upload?
我在http://tfs.visualstudio.com上在云中玩TFS .我有一台新电脑,想要下载我的解决方案.我看到如何从VS连接到TFS,我可以在VS中看到我的工作项,但我看不到我的源代码.
我将使用Git或Mercurial术语来表达这一点; 如何将repo克隆到我的新PC?
我看到了几个先前已经回答过的关于在C#中向IEnumerable添加项目的问题,但是当我试图在VB.NET中实现所提出的解决方案时,我感到困惑.
Option Strict On
Dim customers as IEnumerable(Of Customer)
' Return customers from a LINQ query (not shown)
customers = customers.Concat(New Customer with {.Name = "John Smith"})
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了错误:
Option Strict On禁止从Customer到IEnumerable(Of Customer)的隐式转换
然后VS2008建议使用CType,但这会导致运行时崩溃.我错过了什么?
我的Visual Studio 2008解决方案包含C#和VB.NET项目.从VB.NET项目中,如何访问C#属性,并将其访问修饰符设置为"internal"?
如何在.NET中捕获内部异常?我需要检查2个数据库以获取记录.如果找不到记录,数据库代码会抛出异常,因此我想检查第二个数据库:
Try
# Code to look in database 1
Catch ex as DataServiceQueryException
Try
# Code to look in database 2
Catch ex2 as DataServiceQueryException
throw New DataServiceQueryException(ex.Message, ex2) # Fails here
End Try
Catch ex as Exception # Why doesn't ex2 land here?
# Tell user that data was not found in either database
End Try
Run Code Online (Sandbox Code Playgroud)
上面的伪代码失败了'Fails here,ex2永远不会被我的代码处理.
我该如何正确处理内部异常?