使用VS 2008,我有一个Repeater控件:
<asp:Repeater runat="server" ID="storesRep" DataSourceID="storeSqlDataSource"
OnItemDataBound="StoresRep_ItemDataBound">
<ItemTemplate>
<table style="padding:0px">
<tr>
<td style="width:200px"><asp:Label ID="infoLbl" runat="server">
Choose stores for upload:</asp:Label>
</td>
<td style="width:110px">
<asp:Label ID="storeLbl" runat="server" Text='<%# Bind("Name") %>'>
</asp:Label>
</td>
<td><asp:CheckBox runat="server" ID="storeCheck" /></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="storeSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:someConnectionString %>"
SelectCommand="SELECT [StoreId], [Name] FROM [Store] Order By [Name]">
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
现在,如果数据源没有从数据库返回任何项目,我想显示默认文本,如"找不到商店".到目前为止,我主要使用的GridView是因为EmptyDataText属性而没有问题的地方.
我正在尝试在我的身份验证系统中实现JWT,我有几个问题.要存储令牌,我可以使用cookie,但也可以使用localStorage或sessionStorage.
哪个是最好的选择?
我已经读过JWT保护网站免受CSRF的侵害.但是,我无法想象假设我将JWT令牌保存在cookie存储中会如何工作.
那么它将如何保护CSRF?
更新1
我看到了一些使用示例,如下所示:
curl -v -X POST -H "Authorization: Basic VE01enNFem9FZG9NRERjVEJjbXRBcWJGdTBFYTpYUU9URExINlBBOHJvUHJfSktrTHhUSTNseGNh"
Run Code Online (Sandbox Code Playgroud)
当我从浏览器向服务器发出请求时,如何实现?我还看到有些人在URL中实现了令牌:
http://exmple.com?jwt=token
Run Code Online (Sandbox Code Playgroud)
如果我通过AJAX发出请求,那么我可以设置一个标题jwt: [token],然后我可以从标题中读取标记.
更新2
我安装了高级REST客户端谷歌浏览器扩展,并能够将令牌作为自定义标头传递.在向服务器发出GET请求时,是否可以通过Javascript设置此标头数据?
可能是一个愚蠢的问题,但我在网上找不到任何解释.
这段代码不起作用的具体原因是什么?该代码应该将属性值从Contact(源)复制到新实例化的ContactBO(目标)对象.
public ContactBO(Contact contact)
{
Object source = contact;
Object destination = this;
PropertyInfo[] destinationProps = destination.GetType().GetProperties(
BindingFlags.Public);
PropertyInfo[] sourceProps = source.GetType().GetProperties(
BindingFlags.Public);
foreach (PropertyInfo currentProperty in sourceProps)
{
var propertyToSet = destinationProps.First(
p => p.Name == currentProperty.Name);
if (propertyToSet == null)
continue;
try
{
propertyToSet.SetValue(
destination,
currentProperty.GetValue(source, null),
null);
}
catch (Exception ex)
{
continue;
}
}
}
Run Code Online (Sandbox Code Playgroud)
两个类都具有相同的属性名称(BO类有一些其他类,但它们在初始化时无关紧要).这两个类都只有公共属性.当我运行上面的例子,destinationProps 并且 sourceProps长度为零.
但是当我扩展GetProperties方法时BindingFlags.Instance,它会突然返回所有内容.我很感激,如果有人可以解释这件事,因为我迷路了.
以下代码有效,但我想知道MemoryStream创建是否正确关闭.应该如何执行或FileStreamResult为我处理它?
public FileStreamResult DownloadBudgetedRoleOpportunities(
Guid projectGuid,
IEnumerable<Guid> guidRequiredRoles)
{
var rolebroker = new ProjectRoleBudgetBroker();
var memstream = rolebroker.CreateBudgetedRoleOpportunies(
projectGuid,
guidRequiredRoles);
var fsr = new FileStreamResult ( memstream, "application/csv" )
{
FileDownloadName = "RoleOpportunities.csv"
};
// memstream.Close(); throws exception
return fsr;
}
Run Code Online (Sandbox Code Playgroud) 目前我有以下代码:
ContextMenuStrip contexMenuuu = new ContextMenuStrip();
contexMenuuu.Items.Add("Edit ");
contexMenuuu.Items.Add("Delete " );
contexMenuuu.Show();
Run Code Online (Sandbox Code Playgroud)
如何在单击项目时添加要处理的事件?
我想创建一个适用于任何数据提供者的数据访问层.
我知道可以DbCommand使用连接上可用的工厂方法创建一个.
objDbCon.CreateCommand();
Run Code Online (Sandbox Code Playgroud)
但是,我找不到任何可以创建的东西DbDataAdapter.这是ADO.NET中的一个错误还是什么?
装配GetTypes()在幕后做什么?假设已经加载了一个程序集AppDomain,它还需要从物理DLL中读取吗?汇编清单的作用是什么?
通过这样的程序集迭代:
AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes())
Run Code Online (Sandbox Code Playgroud)
我偶尔会收到以下错误:
Could not load file or assembly
Run Code Online (Sandbox Code Playgroud)
这告诉我,因为一个程序集被加载到AppDomain它不一定完全加载到内存.有时它仍然需要返回文件.
我的问题:
我创建了一个应用程序,它只使用服务器在正确的登录凭据上发送的JWT,并授权/api我的后端Express.js服务器上的任何路由.
另一方面,AngularJS使用此令牌,将其存储在会话存储中,并且每次使用auth拦截器将令牌发送回服务器.
我最近才明白这种做法有多危险.
在这种情况下,我理解来回传递令牌的方法.但是,如果您希望将JWT存储在客户端Javascript无法读取的安全的,仅HTTP的cookie中,那么有人会非常善意地解释发生的方法吗?
例如:凭证成功
我试图在这里获得一个关于它是如何工作的心智模型.如果我的理解是正确的,那么这样做就不再需要auth拦截器,因为在正确的凭证登录时,服务器将在cookie内完成所有的令牌传输.
我正在使用以下代码
// Model
[DisplayFormat(
ApplyFormatInEditMode = true,
DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime StartDate { get; set; }
// View
@Html.EditorFor(model => model.StartDate)
Run Code Online (Sandbox Code Playgroud)
格式化,StartDate但结果是xx-xx-xxxx而不是xx/xx/xxxx.如何解决这个问题并始终使用xx/xx/xxxx格式?
更新:
改变文化en-US似乎工作:
var culture = new CultureInfo(userCulture);
System.Threading.Thread.CurrentThread.CurrentCulture = "en-US";
System.Threading.Thread.CurrentThread.CurrentUICulture = "en-US";
Run Code Online (Sandbox Code Playgroud)
但这不是一个解决方案,因为我可能正在使用不同的文化,我仍然希望以不同的方式显示日期.
如果当前文化告知应显示日期,dd-MM-yyyy则使用DisplayFormat上述方法无效并且日期不显示dd/MM/yyyy.
如果我在C#中有部分类,文件名应该是什么?
该类被调用,partial class Logic并且将存在于两个或三个单独的文件中.
c# ×5
.net ×3
cookies ×2
jwt ×2
reflection ×2
ado.net ×1
angularjs ×1
asp.net ×1
contextmenu ×1
events ×1
express ×1
javascript ×1
memorystream ×1
passport.js ×1
repeater ×1
security ×1
web-services ×1
windows ×1