我有一个名为LoginController的控制器,其Get方法的签名为:
public string Get(string Key, string Code, string UserID, string Password)
Run Code Online (Sandbox Code Playgroud)
我希望能够通过类似于以下的调用来调用它:
http://localhost:1234/api/Login/KeyValue/CodeValue/UserValue/PasswordValue
Run Code Online (Sandbox Code Playgroud)
我不能让这个工作.如果我用以下方式调用呼叫:
http://localhost:1234/api/Login?Key=KeyValue&Code=CodeValueUserID=UserValue&Password=PasswordValue
Run Code Online (Sandbox Code Playgroud)
通话成功.
我已经尝试将下面的路由添加到Global.asax
routes.MapHttpRoute(name: "Login", routeTemplate: "api/{controller}/{action}/{Key}/{Code}/{UserID}/{Password}",
defaults: new { Key = UrlParameter.Optional, Code = UrlParameter.Optional, UserID = UrlParameter.Optional, Password = UrlParameter.Optional });
Run Code Online (Sandbox Code Playgroud)
要么
routes.MapHttpRoute(name: "Login", routeTemplate: "api/{controller}/{Key}/{Code}/{UserID}/{Password}",
defaults: new { Key = UrlParameter.Optional, Code = UrlParameter.Optional, UserID = UrlParameter.Optional, Password = UrlParameter.Optional });
Run Code Online (Sandbox Code Playgroud)
这些似乎不起作用.我哪里出错或者这是否可能?我能够在带有MVC3的RC版WebApi中做到这一点.
我正在开发一个 MVC 应用程序,我正在使用 Unity 进行 IoC。我的应用程序基本上由 UI 层、服务层和存储库层组成。
我的典型控制器是:
public class TestController : Controller
{
private ITestService testServ;
public TestController(ITestService _testServ)
{
testServ= _testServ;
}
public ActionResult Index()
{
testServ.DoSomething();
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
没有什么异常,我的每个控制器都注入了一个服务对象。我的服务层对象执行复杂的业务规则,聚合来自许多不同存储库的信息。通过使用 IoC,我发现我的构造函数看起来过于复杂,但由于该服务需要访问许多存储库,我看不到任何解决此问题的方法。
我的服务层中的典型类如下所示:
public class TestService : ITestService
{
private ITransactionRepository transRepo;
private IAccountRepository accountRepo;
private ISystemsRepository sysRepo;
private IScheduleRepository schRepo;
private IProfileRepository profileRepo;
public TestService(ITransactionRepository _transRepo;
IAccountRepository _accountRepo;
ISystemsRepository _sysRepo;
IScheduleRepository _schRepo;
IProfileRepository _profileRepo)
{
transRepo = _transRepo;
accountRepo = _accountRepo;
sysRepo = _sysRepo;
schRepo …Run Code Online (Sandbox Code Playgroud) 我有一个主ID为ID的表,该字段不是标识列.我对Entity Framework 6的迁移是
CreateTable(
"dbo.Action",
c => new
{
ID = c.Int(nullable: false, identity: false),
ActionName = c.String(maxLength: 50),
})
.PrimaryKey(t => t.ID);
Run Code Online (Sandbox Code Playgroud)
这一切看起来都很直接.然后我有一个方法来播种一些数据:
public static void Seed(this DbSet<Action> entitySet)
{
MainContext dbCtx = DataRepositoryBase<Action>.GetContext(entitySet) as MainContext;
if (dbCtx != null)
{
entitySet.Add(new Action()
{
ID = 1,
ActionName = "Test"
});
}
}
Run Code Online (Sandbox Code Playgroud)
就在这时我得到了一个错误
"不能将NULL值插入列'ID’,表'dbo.Action’;列不允许空INSERT失败\ r \n该语句已终止."
如您所见,我显然为ID列提供了一个值.我怀疑实体框架期望ID是一个Identity列
Entity类非常简单
[DataContract]
public class Action
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string ActionName { get; set; …Run Code Online (Sandbox Code Playgroud) 我有一个标准的ASP.Net应用程序,我在其中添加了Azure部署项目以部署到Azure.该应用程序可以很好地部署到Azure.
然后我想扩展它以启动任务.
我将以下内容添加到ServiceDefintion.csdef中
<Startup>
<Task commandLine="startup.cmd" executionContext="elevated" taskType="simple"/>
</Startup>
Run Code Online (Sandbox Code Playgroud)
startup.cmd位于应用程序bin文件夹中.我已经记录了命令文件,所以我可以看到它没有被执行.
当我将相同的应用程序部署到本地计算机上的Compute Emulator时,启动任务正确执行.
我错过了什么吗?
我正在使用IdentityServer4和MVC客户端。当客户端会话期满时,我希望我的用户被迫再次登录。但是,无论我做什么,IdentityServer似乎都会在会话结束时自动将用户重新登录。
我在客户端的启动时间是(会话需要30秒才能测试)
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies", options => { options.ExpireTimeSpan = new TimeSpan(0, 0, 30); })
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("Billing");
options.Scope.Add("offline_access");
options.UseTokenLifetime = false;
});
Run Code Online (Sandbox Code Playgroud)
然后我在IdentityServer中的配置如下:
new Client
{
ClientId = "Test",
ClientName = "Test",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
AlwaysIncludeUserClaimsInIdToken = true,
RequireConsent = false,
IdentityTokenLifetime = 30,
AccessTokenLifetime = 30,
ClientSecrets =
{
new Secret("secret".Sha256())
},
RedirectUris …Run Code Online (Sandbox Code Playgroud) 我试图运行一个简单的webjob,它基本上打开端口并监听它们的流量.我希望能够使用80或443的其他端口.我的代码是:
var listeningOn = string.Format("http://wwwmydomain.com:4027,
var appHost = new AppHost();
appHost.Init();
appHost.Start(listeningOn);
Run Code Online (Sandbox Code Playgroud)
一旦我启动AppHost,我收到一个错误说明:
未处理的异常:System.Net.HttpListenerException:在System.Net.HttpListener.SetupV2Config()[10/06/2015 15:04:49>中拒绝访问[10/06/2015 15:04:49> ccdf79:ERR] ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.Start(String urlBase)中的System.Net.HttpListener.Start()[10/06/2015 15:04:49> ccdf79:ERR]中的ccdf79:ERR]
有没有办法解决这个问题,或者是我使用虚拟机的唯一选择.我曾调查过Azure流量管理,但这似乎并不适合我的需求.我需要使用端口4027的内部原因是我无法控制的.
除了聚合不同之外,我有几个几乎相同的查询.我正在尝试创建一个可以传递聚合函数的方法.到目前为止我的努力看起来像
public void ExecQuery(Func<IEnumerable<testtable>, float?> filter)
{
var results = from a in testtable
group a by a.TransactionDate.Month into j
select new
{
Month = j.Key,
Total = filter
};
}
Run Code Online (Sandbox Code Playgroud)
我希望能够使用它来调用它
ExecQuery(c => c.Sum(a=>a.Price));
ExecQuery(c => c.Count());
Run Code Online (Sandbox Code Playgroud)
我觉得我很亲密.
c# ×5
azure ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
identity ×1
lambda ×1
linq ×1
networking ×1
parameters ×1
port ×1
primary-key ×1
rest ×1
sql-server ×1
startup ×1
task ×1
windows ×1