ControllerBaseclass has Challenge方法,返回ChallengeResult类的对象.
CookieAuthenticationOptions班AutomaticChallenge有财产.
我认为ChallengeResult与外部登录有关.但它是如何实际工作的?"挑战"一词来自哪里?这里面有什么.
我有一个包含两个表not null列Created和Updated.
我写了相应的触发器
ALTER TRIGGER [dbo].[tr_category_inserted] ON [dbo].[Category]
AFTER INSERT
AS
BEGIN
UPDATE Category
SET Created = GETDATE(), Updated = GETDATE()
FROM inserted
WHERE Category.ID = inserted.ID;
END
Run Code Online (Sandbox Code Playgroud)
和
ALTER TRIGGER [dbo].[tr_category_updated] ON [dbo].[Category]
AFTER UPDATE
AS
BEGIN
UPDATE Category
SET Updated = GETDATE()
FROM inserted
inner join [dbo].[Category] c on c.ID = inserted.ID
END
Run Code Online (Sandbox Code Playgroud)
但如果我插入一个新行,我会收到一个错误
无法将值NULL插入"创建"列,表"类别"; 列不允许空值.INSERT失败.
插入命令:
INSERT INTO [Category]([Name], [ShowInMenu], [Deleted])
VALUES ('category1', 0, 0)
Run Code Online (Sandbox Code Playgroud)
如何在没有设置这些列的情况下编写此类触发器以允许null?
interface IConverter {
convert(value: number): string
}
class Converter implements IConverter {
convert(): string { // no error?
return '';
}
}
const v1: IConverter = new Converter();
const v2: Converter = new Converter();
v1.convert(); // error, convert has parameter, although Converter's convert doesn't expect one
v2.convert(); // ok, convert has no parameters, although Converter implements IConverter which should has paramater
Run Code Online (Sandbox Code Playgroud)
Converterimplements IConverter,它有一个带有一个参数的方法,但Converter缺少这个参数.如果我们不完全实现此接口,为什么TS编译器不会引发错误?
我有这个小代码示例:
public class ValueController : ApiController
{
private EstateContext _db;
public ValueController()
{
_db = new EstateContext();
}
[HttpPost]
public async void DoStuff(string id)
{
var entity = await _db.Estates.FindAsync(id); //now our method goes out and Dispose method is calling
//returns here after disposing
_db.SaveChanges(); // _db is disposed
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_db.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
每个ApiController/Controller都实现了IDisposable接口.所以在Dispose方法中我想释放任何资源,比如DbContext.但是如果使用async,则此Dispose方法在第一次出现await时调用.所以在等待之后我已经处理了DbContext.那么在使用异步时处理EF上下文的最佳方法是什么?事实证明,在控制器中不可能依赖Dispose方法?
是否SqlDataAdapter关闭SqlConnection后Fill()功能还是需要关闭它自己?
string cnStr = @"Data Source=TEST;Initial Catalog=Suite;Persist Security Info=True;User ID=app;Password=Immmmmm";
cn = new SqlConnection(cnStr);
SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Date", cn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
cn.Close() // ????????
Console.WriteLine(ds.Tables[0].Rows.Count);
Console.WriteLine(cn.State);
Run Code Online (Sandbox Code Playgroud) 有没有办法使用错误行号的输出验证XSD架构上的XML文件?
XmlReader阅读器不允许使用行号,它只显示元素名称.
我有这个POST动作:
[HttpPost]
public ActionResult GetReport(GetReportModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
return View("GetReport", new GetReportModel()
{
Identifier = "test",
Permission = true
});
}
Run Code Online (Sandbox Code Playgroud)
当我发布表单时,执行此操作后,生成的视图中没有任何更改.我的意思是,TextBoxfor Identifier没有我在动作中设置的"test"字符串值.但如果我清除ModelState,View将显示新值:
[HttpPost]
public ActionResult GetReport(GetReportModel model)
{
if (!ModelState.IsValid)
{
return View();
}
ModelState.Remove("Identifier");
ModelState.Remove("Permission");
return View("GetReport", new GetReportModel()
{
Identifier = "test",
Permission = true
});
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会这样?如果模型状态无效,为什么每个人都将模型返回到View?例如,Microsoft的默认项目模板具有以下代码:
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
return RedirectToLocal(returnUrl);
}
// Why do they pass the …Run Code Online (Sandbox Code Playgroud) 考虑这个示例代码
System.Collections.ArrayList fruits = new System.Collections.ArrayList();
fruits.Add("mango");
fruits.Add("apple");
fruits.Add("lemon");
IEnumerable<string> query = fruits.Cast<string>()
.OrderBy(fruit => fruit)
.Where(fruit => fruit.StartsWith("m"))
.Select(fruit => fruit);
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
Select如果自己Where返回相同的类型,是否需要编写最后一个子句?这个例子来自msdn,为什么他们总是写它?Select和Where,或OrderBy?对不起我的英语不好.我对XmlSerializer很奇怪.这是我的代码
[Serializable]
public class Radio
{
public bool hasSubWoofers;
public double[] stationPresets;
[XmlIgnoreAttribute]
public string radioId = "X-3454";
}
[Serializable]
public class Car
{
public Radio radio = new Radio();
public int speed;
}
[Serializable]
public class JamesBondCar : Car
{
public bool canFly;
public bool canSubmerge;
private string flag = "string flag";
}
Run Code Online (Sandbox Code Playgroud)
class JamesBondCar有私有成员'flag',在序列化期间,XmlSerializer不应该序列化它.在XML中,我正在寻找它.是'标志'字段:
<JamesBondCar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<radio>
<hasSubWoofers>true</hasSubWoofers>
<stationPresets>
<double>192.3</double>
<double>45.2</double>
<double>456.3</double>
</stationPresets>
</radio>
<speed>342</speed>
<canFly>true</canFly>
<canSubmerge>false</canSubmerge>
</JamesBondCar>
Run Code Online (Sandbox Code Playgroud)
但是,这是主要功能:
JamesBondCar bond = new JamesBondCar();
bond.canFly = true; …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×4
asp.net-mvc ×3
sql-server ×2
t-sql ×2
asp.net ×1
asp.net-core ×1
http-post ×1
linq ×1
sql ×1
triggers ×1
typescript ×1