C# 如何将此C代码转换为VB;context.OwinContext.Response.Headers.Add(";访问控制允许源代码";,新[]{";*";})&引用;
考虑一下这个C代码: 当我使用Telerik's online翻译以下代码时,我在这一行中遇到一个错误:C# 如何将此C代码转换为VB;context.OwinContext.Response.Headers.Add(";访问控制允许源代码";,新[]{";*";})&引用;,c#,.net,vb.net,C#,.net,Vb.net,考虑一下这个C代码: 当我使用Telerik's online翻译以下代码时,我在这一行中遇到一个错误: context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", New () {"*"})` 错误是: 无法解析响应 我的输入文件如下所示: public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider {
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", New () {"*"})`
错误是:
无法解析响应
我的输入文件如下所示:
public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (AuthRepository _repo = new AuthRepository())
{
IdentityUser user = await _repo.FindUser(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
context.Validated(identity);
}
}
这就意味着:
Public Class SimpleAuthorizationServerProvider
Inherits OAuthAuthorizationServerProvider
Public Overrides Function ValidateClientAuthentication(context As OAuthValidateClientAuthenticationContext) As Task
context.Validated()
End Function
Public Overrides Function GrantResourceOwnerCredentials(context As OAuthGrantResourceOwnerCredentialsContext) As Task
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", New () {"*"})
Using _repo As New AuthRepository()
Dim user As IdentityUser = Await _repo.FindUser(context.UserName, context.Password)
If user Is Nothing Then
context.SetError("invalid_grant", "The user name or password is incorrect.")
Return
End If
End Using
Dim identity = New ClaimsIdentity(context.Options.AuthenticationType)
identity.AddClaim(New Claim("sub", context.UserName))
identity.AddClaim(New Claim("role", "user"))
context.Validated(identity)
End Function
End Class
如何更正翻译以使生成的Visual Basic代码正常工作?该语句的翻译似乎不正确,应该正确
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", { "*" })
没有New()该语句的翻译似乎不正确,应该是正确的
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", { "*" })
如果没有New()你的问题是什么?你的问题是什么?我已经尝试过了,而且它是这样工作的,但是我认为object param应该是一个{*}数组。如果我错了,请纠正我,谢谢你的帮助answer@Xvegas{“”}创建一个包含单个元素(“”)的字符串数组。我是一个c#guy,但如果我理解这一点()正确的话,在VB.net中
{..}
创建了一个匿名类型,并且该数组被暗示等同于c#中的new[]{..}
。我想不管怎样,我已经尝试过了,它是这样工作的,但是我认为对象参数应该是一个{*}数组,如果我错了,请纠正我,谢谢你的帮助answer@Xvegas{“”}用一个元素(“”)创建一个字符串数组。我是一个c#guy,但是如果我正确地理解了这个(),那么在VB.net{..}
创建一个匿名类型,并且该数组隐含等同于c#中的new[]{…}
。我想无论如何